472,958 Members | 2,226 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

how to have forward declaration from different namespace?

Hi,
I have two namespace contains class InkFrame and PrefDialog
respectively. PrefDialog needs InkFrame to show the dialog over the
frame. It also stores a pointer to InkFrame inside it.
Now I want InkFrame to be forward declared in the PrefDialog header
file rather than to be included. I want to include it in the cpp file
instead. There is no harm including it in PrefDialog header, and it
works. But I want to save some compilation time. That is why I thought
to forward declare it (and all the other classes whenever possible)
instead of include. They works perfectly if both of them are from same
namespace. But fails to work if they are from different namespace.

To make it little clear, the headers are
InkFrame.hpp =>
namespace ui{
class InkFrame : public Frame{
...
} ;
}
here Frame, is a library class and necessary headers are already there.

PrefDialog.hpp =>
#include "InkFrame.hpp" //and other necessary headers.
using ui::InkFrame
namespace client{
namespace ui{
class PrefDialog : public Dialog{
InkFrame* _parent;
public:
PrefDialog(InkFrame* parent);
};
}
}
This code works.
Next I removed include & have forward declaration. The include and
using statement is shifted to cpp file for PrefDialog.
PrefDialog.hpp =>
//#include "InkFrame.hpp" //and other necessary headers.
//using ui::InkFrame
namespace client{
namespace ui{
class InkFrame; //forward declaration.
class PrefDialog : public Dialog{
InkFrame* _parent;
public:
PrefDialog(InkFrame* parent);
};
}
}
Here, the code assumes InkFrame is from client::ui (which is quite
reasonable, I think) and fails to compile the code as cpp gets it from
ui namespace.
declaring at top class ui::InkFrame also do not work, as the ui
namespace is not defined here!
also declaring like
namespace ui{
class InkFrame;
}
at the top is not working. These two cases the header do not see the
declaration even, while in the firest case it see and find a mismatch
at the cpp.

Thus, what is the common way to forward declare a class from a
different namespace?

Thanks for any advice.
abir

Sep 11 '06 #1
1 5285

toton wrote:
Hi,
I have two namespace contains class InkFrame and PrefDialog
respectively. PrefDialog needs InkFrame to show the dialog over the
frame. It also stores a pointer to InkFrame inside it.
Now I want InkFrame to be forward declared in the PrefDialog header
file rather than to be included. I want to include it in the cpp file
instead. There is no harm including it in PrefDialog header, and it
works. But I want to save some compilation time. That is why I thought
to forward declare it (and all the other classes whenever possible)
instead of include. They works perfectly if both of them are from same
namespace. But fails to work if they are from different namespace.

To make it little clear, the headers are
InkFrame.hpp =>
namespace ui{
class InkFrame : public Frame{
...
} ;
}
here Frame, is a library class and necessary headers are already there.

PrefDialog.hpp =>
#include "InkFrame.hpp" //and other necessary headers.
using ui::InkFrame
namespace client{
namespace ui{
class PrefDialog : public Dialog{
InkFrame* _parent;
public:
PrefDialog(InkFrame* parent);
};
}
}
This code works.
Next I removed include & have forward declaration. The include and
using statement is shifted to cpp file for PrefDialog.
PrefDialog.hpp =>
//#include "InkFrame.hpp" //and other necessary headers.
//using ui::InkFrame
namespace client{
namespace ui{
class InkFrame; //forward declaration.
class PrefDialog : public Dialog{
InkFrame* _parent;
public:
PrefDialog(InkFrame* parent);
};
}
}
Here, the code assumes InkFrame is from client::ui (which is quite
reasonable, I think) and fails to compile the code as cpp gets it from
ui namespace.
declaring at top class ui::InkFrame also do not work, as the ui
namespace is not defined here!
also declaring like
namespace ui{
class InkFrame;
}
at the top is not working. These two cases the header do not see the
declaration even, while in the firest case it see and find a mismatch
at the cpp.

Thus, what is the common way to forward declare a class from a
different namespace?

Thanks for any advice.
abir
Got the answer!
I also need to write
using ui::InkFrame or fully quilified name inside the class as type,
along with forward declaration like
namespace ui{
class InkFrame;
}
Thanks to the newsgroup ...

Sep 11 '06 #2

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

Similar topics

5
by: John Gabriele | last post by:
I'm hoping someone can please help me remember the C++ rule: When you're writing a header file for a class (say, some_namespace::Bar), and that class makes use of another class...
2
by: John Ratliff | last post by:
I'm having issues with forward declarations and possibly member variables. Can you declare a member variable and pass it parameters. class x { private: y obj(this); } Is that valid? I'm...
3
by: Libertadrian | last post by:
Hi again, Maybe I missed something, but I cannot do a forward declaration in managed C++. By doing: namespace Namespace {
3
by: Eckart Haug | last post by:
I'm working with C# objects from managed C++ using the gcroot template. There'a a C++ header containing the definition of a C++ class: #using <mscorlib.dll> #include <vcclr.h> #using...
4
by: yuliy | last post by:
Hello gurus, I stuck in following: how can I do forward declaration if the forward declared class is in some namespace? something like // header class std::string; // approach#1
1
by: ctor | last post by:
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...
2
by: flopbucket | last post by:
Hi, How can I forward declare a class that is in a different namespace? As a simple example: classs Foo { std::string *string; };
3
by: yancheng.cheok | last post by:
hello all, how can i make, a forward declaration class's enum member, being visible by another class? consider the following case, ---------------------------- dog.h...
1
by: dj | last post by:
How can I make a forward declaration of a class that is defined in some other namespace? E.g.: file1.h: namespace A { class A {...}; } file2.h:
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.