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