C++ Namespaces

Posted on 2011-10-11
Medium Priority
Last Modified: 2012-05-12
I am testing this simple C++ namespace in netbeans.

I have this namespace.... in a ANameSpace.h file...
#define      ANAMESPACE_H

namespace ANameSpace
    class AClass
         AClass() {
     this->aValue = 0;

 AClass(const AClass& orig) {

void  aMethod(int inValue){
    this->aValue = inValue;

  ~AClass() {
        int aValue;

#endif      /* ANAMESPACE_H */

Then I have a small main() like this....

#include <cstdlib>
using namespace std;
using namespace ANameSpace;

int main(int argc, char** argv)
  ANameSpace::AClass aClass;
  return 0;

I am getting abuild error at line : using namespace ANameSpace;
main.cpp:19: error: `ANameSpace' has not been declared

and also in line : ANameSpace::AClass aClass;

 `ANameSpace' has not been declared

Question by:prain
  • 2
LVL 75

Accepted Solution

käµfm³d   👽 earned 500 total points
ID: 36950287
Is this all in the same file? If not, I don't see where you included the header for "ANameSpace.h" in your main program.

Author Comment

ID: 36950565
OK. Thanks. I thought since they are all part of the same project, I do  not need to put the #inlude "ANameSpace.h"

Author Closing Comment

ID: 36950569
Thanks. Great.

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question