473,323 Members | 1,589 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,323 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 5357

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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.