By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,851 Members | 2,104 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,851 IT Pros & Developers. It's quick & easy.

member typedefs

P: n/a
Hello,

I've got few questions concerning typedefs inside class definition.
Firstly, I'll give an example code:
template< class T >
class Function {
public:
typedef boost::shared_ptr< Function< T > > Pointer;
(...)
};

template< class T >
std::ostream& operator<<(std::ostream& o, boost::shared_ptr<Function<T>
P) {

//std::ostream& operator<<(std::ostream& o, typename
Function<T>::Pointer P) {
return o << *P;
}

(...)

int main()
{
Function<int>::Pointer A(new Function<int>());
std::cout << A << std::endl;
}


Function<int>::Pointer is properly recognized as a type (and that
equals to boost::shared_ptr< Function <T> >). But why does the compiler
complain that Function<T>::Pointer is a implicit typename? Is that
really impossible to find that Function<T>::Pointer is a typename?
Adding typename before Function<T>::Pointer makes that warning
disappear, however the templated operator<<() overload doesn't work as
desired. The second line of main function instead of executing my
overloaded operator<<(), displays address, so it performs as if there
was no overload at all. I thought that maybe ostream operator<< of
shared_ptr is so strictly bound to it that it isn't possible to
overload it. But that appeared not to be true. When I replaced that
with type description I thought it was equivalent to

(boost::shared_ptr< Function<T> >), it worked - main() called my
overloaded operator<<() instead of the default one. So in the context
of the example given above, these two declarations (one of them is

commented out in the example) are not equivalent.

Is a behaviour in such cases specified by the standards?
Is it a bug in the compiler I am using (GCC 3.3.5)?
Or maybe I misunderstood the idea of member typedefs?
Is it possible to workaround this problem and get the behaviour I
expect (that is: create a working templated operator overload (ab)using
member typedefs)?
Thanks,
Michal

Dec 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Michal Wróbel wrote:
Hello,
.... ... But why does the compiler
complain that Function<T>::Pointer is a implicit typename?


This is usually because you need to prefix it with "typename" as
required by the standard.

Since I can't compile your code I can't really tell what the compiler is
complaining about.
Dec 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.