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

Forward typedefs

P: n/a
Hello,

It's possible to do a forward declaration of a typedef?

Something similar to

typedef TMyType; // typedef forward
declaration

void f ( TMyType& t )
{
// do something with t
}

...

typedef double TMyType; // typedef declaration
The code above doesn't compile.

In Item 37 of "More Exceptional C++", Herb Sutter says that is not
possible to do a forward declaration of std::ostream ( that is a typedef )
because it's part of the std namespace. Does this means that typedef forward
declarations for non-std members are possible?

Thanks.
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Jorge Yez wrote:
It's possible to do a forward declaration of a typedef?
No. What are you trying to accomplish?
Something similar to

typedef TMyType; // typedef forward
declaration

void f ( TMyType& t )
{
// do something with t
}

...

typedef double TMyType; // typedef declaration
The code above doesn't compile.
It's incorrect. There's this:

template <typename T> void f (T & t)
{
// do something with t
}

double x;
f (x);
In Item 37 of "More Exceptional C++", Herb Sutter says that is not
possible to do a forward declaration of std::ostream ( that is a typedef )
because it's part of the std namespace. Does this means that typedef forward
declarations for non-std members are possible?


No.

--
Regards,
Buster
Jul 22 '05 #2

P: n/a
On Fri, 17 Dec 2004 09:20:48 +0100 in comp.lang.c++, "Jorge Yez"
<jy****@preference.es> wrote,
In Item 37 of "More Exceptional C++", Herb Sutter says that is not
possible to do a forward declaration of std::ostream ( that is a typedef )
because it's part of the std namespace.


You cannot forward declare std::ostream because it is a typedef of a
tricky instance of a templated class, and the class must be declared
before you can typedef it, and you do not know or want to know
enough to properly and exactly declare that class. If you just
tried to write
namespace std { class ostream; };
it would contradict the correct definition when it comes along
later.

The library author knows about those things, and can forward declare
std::ostream. Have a look at the contents of your compiler's
#include <iosfwd>
which is provided for that purpose.

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.