473,395 Members | 1,978 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,395 software developers and data experts.

Cannot see namespace outside the namespace of a declared class

Hello,

I have a problem with declaring a class in my namespace and using std::string in that class. For example:

Expand|Select|Wrap|Line Numbers
  1. #include <string>
  2.  
  3. namespace A {
  4. class myWindow {
  5. public:
  6.    ...
  7. private:
  8.    std::string title;
  9. };
  10.  
  11. } // end of namespace A
The compiler gives an error like A::std::string not defined.
If I put a
using namespace std;
or a
using std::string;
after the include of string header, the compiler gives the error that title has incomplete type (if I remember correctly, but I'm not sure).

Could someone enlighten me about what the problem is?

Thanks in advance,
Feb 27 '08 #1
3 1690
weaknessforcats
9,208 Expert Mod 8TB
string is defined in the std namespace. That makes the fully qualified name std::string. If this string is in your A namespace, it is still std::string.

Your class is A::myWindow since the class declaration is in the A namespace.
Feb 27 '08 #2
string is defined in the std namespace. That makes the fully qualified name std::string. If this string is in your A namespace, it is still std::string.

Your class is A::myWindow since the class declaration is in the A namespace.
Hi,

thanks for the help, I didn't know that you can refer outside of the current namespace with the fully qualified name. I use that now.

However, actually the problem was that myClass was derived from another class (let's call it Base) in the same namespace (A). class Base had an std::list as a member variable, so I #included <list>, but within the namespace A. That caused the problem, because the compiler included stuff for list as part of that namespace (e.g. A::std::list). And then common code for std::string could not be found.
Feb 29 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
The <list> should not be included in a namespace of your own unless you intend to restrict it.

It's kinda like: if it hurts to bend your arm that way, then don't do it.
Feb 29 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Anonymous | last post by:
Is namespace the same thing as scope? While reading the book "Thinking in C++", I was under the impression that namespace is, well, a namespace--a feature to create a hiearchy for identifiers...
2
by: Wat | last post by:
If a class is not given a namespace, what does this imply? From inside of the class, if to call global functions, should global scope :: be used at all? If global scope :: used, what benefits...
2
by: Tony Johansson | last post by:
Hello! I'm reading a book about C++ and there is something that I don't understand so I ask you. Below I have the text from the book and the code from the file where main is located and some...
3
by: Pranav Shah | last post by:
What is the differrence between using the "using" caluse outside of the namespace definition and inside the namespace. Example Outside: using System; namespace Example.Outside { }
1
by: Yuan Ze | last post by:
The compiler can not compile the code boxing/unboxing value types declared in a MG C++ class. It reports compiler error 2248, 'member' : cannot access member declared in class 'class'. To use a...
3
by: dotNETnews | last post by:
Little confused... When I declare a namespace variable in module I can use it anywhere in the project. That's clear. I read a book in which the author said that namespace variables can be...
5
by: newbie120 | last post by:
Hi all maybe its just been a long day, but i have a question about call access modifiers in C#. Consider the following code. namespace Application { private class Class1 { int i;
7
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; }
14
by: =?ISO-8859-15?Q?Sebastian_Pf=FCtzner?= | last post by:
Hi, the following code produces errors with VC++ and Comeau, but compiles with g++: #include <iostream> namespace n { struct c
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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
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,...
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...

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.