member typedefs

  • Thread starter =?iso-8859-1?q?Michal_Wr=F3bel?=
  • Start date
?

=?iso-8859-1?q?Michal_Wr=F3bel?=

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 said:
//std::eek:stream& operator<<(std::eek:stream& 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
 
G

Gianni Mariani

Michal said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top