473,466 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Forward-declaring classes from different namespaces

Hi,

I'm experimenting with using a lot of different namespaces in my
current project to see if it helps me keep my code more organized. In
some ways I'm finding that it causes more problems than it prevents.

My main issue right now is the clutter that gets added when I
forward-declare classes in other namespaces, but maybe I'm not doing
it right. The only way I've found to do it is as follows:

//FOWARD DECLARATIONS
namespace project {
namespace abc {
class ForwardDecalredClass;
};
};

// CLASS DECLARATION
namespace project {
namespace xyz {
...
};
};

If I need to forward declare classes from more than one namespace, it
gets annoyingly messy. Is there a better way?

Thanks.
Feb 11 '06 #1
1 1758

ctor wrote:
Hi,

I'm experimenting with using a lot of different namespaces in my
current project to see if it helps me keep my code more organized. In
some ways I'm finding that it causes more problems than it prevents.

My main issue right now is the clutter that gets added when I
forward-declare classes in other namespaces, but maybe I'm not doing
it right. The only way I've found to do it is as follows:

//FOWARD DECLARATIONS
namespace project {
namespace abc {
class ForwardDecalredClass;
};
};

// CLASS DECLARATION
namespace project {
namespace xyz {
...
};
};

If I need to forward declare classes from more than one namespace, it
gets annoyingly messy. Is there a better way?


This is pretty much right. One very effective way to prevent clutter is
to limit the number of namespaces. All of your code should reside under
a single (e.g., enterprise) namespace. Then, each "library" should
reside under a single namespace. So, you end up with something like
this:

namespace AllMyCode {

namespace abc { class Foo; }
namespace abc { class Bar; }

namespace def { class Fee; }

namespace hij {

// class definitions

} // close namespace hij
} // close namespace AllMyCode

You only have to open namespace AllMyCode once.

Feb 11 '06 #2

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

Similar topics

3
by: mjm | last post by:
Folks, Please help me with the following problems: ******************************************** 1. I have a class template template<class Base> class Matrix : public Base { /* .... */ }
1
by: qazmlp | last post by:
Is it a good style to re-forward declare the types, which were already forward declared in base header file, in derived class header file? // base.h class addrClass; class base { public:...
7
by: Lynn | last post by:
I am rewriting some memory management code and I need to have a forward declaration of a data structure. I am not converting this data structure into a class (yet). How do I generate a forward...
11
by: aleko | last post by:
This applies equally to function prototypes. Why do we have to tell the compiler twice? Other modern compiled languages don't have this requirement. Just curious, Aleko
2
by: blueblueblue2005 | last post by:
Hi, there was a post several days ago about using forward class declaration to solve the circular including issue, today, one question suddenly came into mind: which class should the forward class...
3
by: db2group88 | last post by:
we are using db2 udb v8.2 on windows. All our tables are created with "not logged initially" parameter. Our application with auto commit on. I would like to do an online backup and rolling forward...
8
by: Tracey | last post by:
Hi, guys. My application requires functionalities like back and forward navigating button on winforms. And there are many forms linking each other. Each form has a pair of buttons of "Back" and...
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;
4
by: aj | last post by:
DB2 LUW v8.2 FP 14 RHAS 2.1 I have a DB2 online DB backup that was done w/ the INCLUDE LOGS option. I am interested in restoring that backup, and rolling forward ONLY the logs contained in the...
7
by: RedLars | last post by:
Need some help with a couple of questions. Previously I have seen this declaration; struct Student { int age; char name; }; and this definition of an object; struct Student stud;
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
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...
1
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
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.