473,386 Members | 1,621 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,386 software developers and data experts.

Forward typedefs

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
2 1846
Jorge Yáñez 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
On Fri, 17 Dec 2004 09:20:48 +0100 in comp.lang.c++, "Jorge Yáñez"
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marcin Kalicinski | last post by:
Hi All, In some headers meant to work with both C and C++ the following is often found: typedef struct tagMyStruct { /*some members*/ } MyStruct; Can I forward-declare MyStruct somehow? ...
5
by: Simon Elliott | last post by:
For some time I've been using typedefs for STL containers for reasons outlined in: http://www.gotw.ca/gotw/046.htm However a major downside to this is that you can't forward declare a typedef...
2
by: Plok Plokowitsch | last post by:
After over a decade of programming in C++ I seem to have missed some substantial point (mental note: am I getting too old for this?). A little bit of help would be *very* appreciated. I'm trying...
23
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
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;
7
by: Michael B Allen | last post by:
I have a forward reference like: struct foo; int some_fn(struct foo *param); Because the parameter is a pointer the compiler is satisfied. But now I wan to change 'struct foo' to a...
28
by: Tom Plunket | last post by:
Hey gang; In C++ I often used forward declarations to allow me to get away with not including additional files in headers, if in fact all I needed was to know that a type existed. e.g. ...
6
by: Hunk | last post by:
Hi I have a question on usage of forward declarations of templates. While searching through this group , people suggested using forward declarations and typedefs for templates as // in...
11
by: Jef Driesen | last post by:
I have the following problem in a C project (but that also needs to compile with a C++ compiler). I'm using a virtual function table, that looks like this in the header file: typedef struct...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.