?
Solved

C++ Namespaces

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

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

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

 AClass(const AClass& orig) {
}

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

  ~AClass() {
}
       
    private:
        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

0
Comment
Question by:prain
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
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.
0
 

Author Comment

by:prain
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"
0
 

Author Closing Comment

by:prain
ID: 36950569
Thanks. Great.
0

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