473,406 Members | 2,404 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,406 software developers and data experts.

Forward decleration of enumerations and typedefs in a NameSpace

Hello,
I have a compilation problem about namespaces:

I have a namespace X in which I declera a type definition:

In X.h file i write:

namespace X {
typedef unsigned int WindowHandle_t;
}

In a class which is in a different namespace ( Y ), I must use the type
definition I declared in namespace X.
MyClass.h file:

Y::MyClass {
....
private:
X::WindowHandle_t handle;
....
}

And the code doesn't compile. I should forward declare this handle type
definition but forward decleration is the same as writing the same
thing that I wrote in X.h file. When I write

In MyClass.h file :

namespace X {
typedef unsigned int WindowHandle_t;
}
Y::MyClass {
....
private:
X::WindowHandle_t handle;
....
}

The code compiles. But as I stated, I do not want to write same type
definition twice in a code. Do you have any suggestions?

Thanks...

Aug 21 '06 #1
3 1833
kasiyil wrote:
Hello,
I have a compilation problem about namespaces:

I have a namespace X in which I declera a type definition:

In X.h file i write:

namespace X {
typedef unsigned int WindowHandle_t;
}

In a class which is in a different namespace ( Y ), I must use the type
definition I declared in namespace X.
MyClass.h file:

Y::MyClass {
....
private:
X::WindowHandle_t handle;
....
}

And the code doesn't compile. I should forward declare this handle type
definition but forward decleration is the same as writing the same
thing that I wrote in X.h file. When I write
Have you included X.h?

--
Ian Collins.
Aug 21 '06 #2
I included it after MyClass.h. There is no way to include it before
MyClass.h .

Ian Collins wrote:
kasiyil wrote:
Hello,
I have a compilation problem about namespaces:

I have a namespace X in which I declera a type definition:

In X.h file i write:

namespace X {
typedef unsigned int WindowHandle_t;
}

In a class which is in a different namespace ( Y ), I must use the type
definition I declared in namespace X.
MyClass.h file:

Y::MyClass {
....
private:
X::WindowHandle_t handle;
....
}

And the code doesn't compile. I should forward declare this handle type
definition but forward decleration is the same as writing the same
thing that I wrote in X.h file. When I write
Have you included X.h?

--
Ian Collins.
Aug 21 '06 #3
kasiyil wrote:
I included it after MyClass.h. There is no way to include it before
MyClass.h .
Why is there no way?

You need to include it from within MyClass.h and before the definition
of MyClass, or move it to another header and do so with the new header.

Forward declaration has nothing to do with this. Even if you could
forward declare a typedef, which unfortunately you don't, it wouldn't
help you because

1. You're returning the type by value so it has to be complete anyway
2. For the sake of clean code you will probably want to put the forward
delcaration in a header anyway.

Jens
Aug 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jorge Yáñez | last post by:
Hello, It's possible to do a forward declaration of a typedef? Something similar to typedef TMyType; // typedef forward declaration void f ( TMyType& t )
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...
14
by: Adam Hartshorne | last post by:
Hi All, I have this stange compiler error. I have a class B that includes pointers to class A, therefore I have done forward referencing by doing class A; at the start of the header file. Ok...
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? ...
2
by: Carlos Martinez Garcia | last post by:
Hi all: I usually make forward declarations in headers. Something like this: class MyClass; Now, I need a reference to a type defined like this (traditional C Style): typedef struct {
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: Till Crueger | last post by:
Hi, I am trying to implement a tree in C and I have the folowing code: struct inner { struct node *left; struct node *right; }; struct leaf {
2
by: Steven T. Hatton | last post by:
This is not a big deal. It just bothers me that I don't see a way around including the header for QVariant in the following: #ifndef _XML_IMPL_INTERNAL_H_ #define _XML_IMPL_INTERNAL_H_ class...
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: 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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.