473,659 Members | 3,631 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1862
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****@prefere nce.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
2812
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? Or more generally, can I forward declare a typedef or an enum? Also, is
5
10366
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 of a STL container: #include <vector> struct foo
2
4506
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 to gather various different classes into a common namespace using typedefs: class QWidget {}; class MyListview {}; namespace gui
23
3841
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? Here's what I thought should work, but apparently doesn't: class Foo; void f1(Foo* p)
7
5985
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
15269
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 typedef'd type like 'foo_t'. The following all fail to compile:
28
1965
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. foo.h: struct Bar;
6
8613
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 myfile.h template<typename T,typename R> class some_class;
11
8310
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 device_t { const device_backend_t *backend; ... } device_t; typedef struct device_backend_t {
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8337
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8531
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.