473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

member typedefs

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
1 1573
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Levent | last post by:
Please consider the following Parent and Child template classes: template <class T> class Parent { public: typedef T type; typedef T& ref; /* pack of typedefs */ };
12
by: Waxhead | last post by:
Note: I'm not experienced with newsgroups so my apologies if I've done any errors. In the function dosomething() I would like to skip the workingstuffptr "workaround". is there any way I can use...
15
by: dutchgoldtony | last post by:
Hi all, I was just wondering if this is possible. I'm trying to implement a viterbi decoder in C and am creating an array of nodes (the struct), and an array of pointers to nodes (the member...
6
by: Bill Rubin | last post by:
The following code snippet shows that VC++ 7.1 correctly compiles a static member function invocation from an Unrelated class, since this static member function is public. I expected to compile the...
30
by: junky_fellow | last post by:
I was looking at the source code of linux or open BSD. What I found that lots of typedefs were used. For example, consider the offset in a file. It was declared as off_t offset; and off_t is...
7
by: Noah Roberts | last post by:
I have something like the following: template<ENUM X, int I = 0> class Generic { .... }; typedef Generic<Val1> v1_type; typedef Generic<Val2> v2_type;
3
by: toton | last post by:
Hi, I want to specialize template member function of a template class . It is creating some syntax problem .... Can anyone say how to do it ? The class is something like this template<typename...
2
by: WaterWalk | last post by:
(Sorry if I duplicated this post. My previous post somehow disappeared.) Hello. I am rather confused about pointers to class data members. Take the following class as an example: class MyClass...
2
by: ds | last post by:
Hi all, what I try to do is the following: template<class Tpclass themap { public: typedef int Tp::*ptr; static std::map<std::string, Tp::ptrsmap;
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.