using your own namespace?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

using your own namespace?

 
0
  #1
Nov 5th, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: using your own namespace?

 
0
  #2
Nov 5th, 2005
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
  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. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: using your own namespace?

 
0
  #3
Nov 5th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: using your own namespace?

 
0
  #4
Nov 5th, 2005
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>
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: using your own namespace?

 
0
  #5
Nov 5th, 2005
Oh, I see. I appreciate the help sunny.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC