943,947 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2515
  • C++ RSS
Nov 5th, 2005
0

using your own namespace?

Expand Post »
I have a class Person and a Class Store. I didn't find any way to really inherit Store in class Person, so I created Class Store in a namespace called StoreClass.

In the person class this doesn't work:

using namespace StoreClass;

it says that namespace StoreClass is undeclared.
I also tried to include the actual File which is called Store.cpp, but it says it couldn't find that either. Both classes are in the same directory.

Is there something I'm doing wrong?
Similar Threads
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Nov 5th, 2005
0

Re: using your own namespace?

No need to add it in the class(not even allowed...i guess).....you can simply put it in global scope or use scope resolution operator...
example
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. namespace z
  4. {
  5. int x=0;
  6. }
  7.  
  8. class Person
  9. {
  10.  
  11.  
  12. public:
  13.  
  14. Person()
  15. {
  16.  
  17. std::cout<<z::x;
  18. }
  19. };
  20.  
  21. int main()
  22. {
  23. Person obj;
  24. return 0;
  25. }
SpS
Reputation Points: 70
Solved Threads: 32
Posting Pro
SpS is offline Offline
598 posts
since Aug 2005
Nov 5th, 2005
0

Re: using your own namespace?

Well, I knew that would work, but I'm trying to split functionality up as much as I can. Is there not a way to have this Store class as an external source code and import it into the Person class?

I've tried this:

#include <Store>

and

#include <Store.cpp>


Both of which didn't work, but they are in the same directoryl
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Nov 5th, 2005
0

Re: using your own namespace?

Quote originally posted by server_crash ...
Well, I knew that would work, but I'm trying to split functionality up as much as I can. Is there not a way to have this Store class as an external source code and import it into the Person class?

I've tried this:

#include <Store>

and

#include <Store.cpp>


Both of which didn't work, but they are in the same directoryl
If they are in same directory then use
#include "Store.cpp" instead of <Store.cpp>
SpS
Reputation Points: 70
Solved Threads: 32
Posting Pro
SpS is offline Offline
598 posts
since Aug 2005
Nov 5th, 2005
0

Re: using your own namespace?

Oh, I see. I appreciate the help sunny.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Adding memberfunctions into a class?
Next Thread in C++ Forum Timeline: Open Source Projects





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC