473,626 Members | 3,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

namespace is not visible in a class?

I include 2 headers: the first defines some namespace A and the second
defines class B which contains some member instances of classes defined in
namespace A.

header1:

namespace A
{
class C;
};

header2:

class B
{
A::C c_instance;
};

Why does the compiler complain during compilation of header2 that A is not a
namespace?

Mar 28 '07 #1
6 2365
On Mar 29, 12:01 am, "r.z." <g...@hjkjhk.pl wrote:
I include 2 headers: the first defines some namespace A and the second
defines class B which contains some member instances of classes defined in
namespace A.

header1:

namespace A
{
class C;

};

header2:

class B
{
A::C c_instance;

};

Why does the compiler complain during compilation of header2 that A is not a
namespace?
My compiler says "field 'c_instance' has incomplete type" when tried.

Could you post some minimal code that shows the error?
Mar 28 '07 #2
My compiler says "field 'c_instance' has incomplete type" when tried.

Could you post some minimal code that shows the error?
just put class C definition instead of its declaration in namespace A and it
shoul give you the same error as me

Mar 28 '07 #3
r.z. wrote:
I include 2 headers: the first defines some namespace A and the second
defines class B which contains some member instances of classes defined in
namespace A.

header1:

namespace A
{
class C;
};

header2:

class B
{
A::C c_instance;
};

Why does the compiler complain during compilation of header2 that A is not a
namespace?
Because you haven't included header1?

--
Ian Collins.
Mar 28 '07 #4
Because you haven't included header1?

it is included - I can use A::C c_instance in main.cpp but not in header2.

Mar 28 '07 #5
On Mar 29, 12:25 am, "r.z." <g...@hjkjhk.pl wrote:
My compiler says "field 'c_instance' has incomplete type" when tried.
Could you post some minimal code that shows the error?

just put class C definition instead of its declaration in namespace A and it
shoul give you the same error as me
Nope, the next compiles fine;
namespace A
{
class C{
public:
C(){};
};
};

class B
{
A::C c;
};

int main(void)
{
B b;
return 0;
}
So, or your compiler is wrong, or there is something else that is
important to the problem in your code that you havn't posted to this
group yet....

Mar 28 '07 #6
SOLVED.
I did forget to include header1 in header2.
I am an ass of a developer.
thanks for comments.

Mar 28 '07 #7

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

Similar topics

4
4578
by: prasat | last post by:
What does namespace signify in C++ -- Posted via http://dbforums.com
2
7482
by: Birt | last post by:
An article states: the global namespace be polluted, causing "a namespace collision." What does this mean exactly? Thank you very much!
3
1677
by: janek | last post by:
I have a question: what differences are between: namespace Mary { int r = 5 ; char m ;
6
24737
by: Robert Warnestam | last post by:
I've two class libraries, where one is referencing the other. The first library looks like this; (assembly name and root name space is set to Codab.Parser) namespace Codab.Parser { public class Parser {...} ... } The second library looks like this (assemble name and root name space is set to Codab.TapNet)
9
5453
by: Ivan Mascovich | last post by:
Previous posts (and compilers) confirm that class X { friend void Y() ; } ; does not match namespace
3
2597
by: Tomás | last post by:
I have a header file/source file combo. There's approximately five functions in the source file. Only one of the functions should be used by other translation units, so I've defined the other four functions within an unnamed namespace. The header file only contains a declaration for the one function. My function needs to call the other four functions. My code won't compile, giving the following error:
3
1814
by: toton | last post by:
Hi, Is it possible to have a class level namespace opening instead of file level . Something like this, I have a long namespace like namespace com { namespace my_company{ namespace my_project{ namespace parser{ class my_parser{ };
7
2068
by: Juha Nieminen | last post by:
This is possible: namespace X { class A; } class X::A { <implementation}; However, what about nameless namespaces? Does this do what I want? namespace { class A; }
3
9540
by: tshad | last post by:
I have a file that I converted from VB.Net to C# that works fine in VB.Net when I compile but not in C# using the same libraries. The error I am getting is: PageInit.cs(9,7): error CS0138: A using namespace directive can only be applied to namespaces; 'System.Web.HttpCookie' is a class not a namespace The code is:
22
3908
by: Luna Moon | last post by:
I am reading the book "C++ Annotations", and here is a quote from the book: Namespaces can be defined without a name. Such a namespace is anonymous and it restricts the visibility of the defined entities to the source file in which the anonymous namespace is defined. Entities defined in the anonymous namespace are comparable to C’s static functions and variables. In C++ the static keyword can still be used, but its use is more
0
8259
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
8192
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
8696
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...
0
8637
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8502
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
4195
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
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
1
1805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1504
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.