954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

using your own namespace?

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?

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

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

#include <iostream>

namespace z
{
	int x=0;
}
	
class Person 
{
	

public:

Person()
 {

	std::cout<<z::x;
}
};

int main()
{
	Person obj;
	return 0;
}
SpS
Posting Pro
599 posts since Aug 2005
Reputation Points: 70
Solved Threads: 32
 

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

and

#include


Both of which didn't work, but they are in the same directoryl

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

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

and

#include

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

SpS
Posting Pro
599 posts since Aug 2005
Reputation Points: 70
Solved Threads: 32
 

Oh, I see. I appreciate the help sunny.

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You