C++ Namespaces

Posted on 2011-10-11
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
    LVL 74

    Accepted Solution

    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

    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

    Thanks. Great.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
    Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now