How to extend class to a class I have in the same file

I have two clasess declared in the same file, below a own namespace.

h file

1
2
3
4
Namespace MYNS {
Class A {.... };

Class B: public MYNS::A {.... };

cpp file
1
2
3
4
5
6
7
MYNS::A() {}
MYNS::~A() {}

....

MYNS::B() : MYNS::A() {}
....


OK , when compile I have :
MYNS::B() : MYNS::A() {} is private

I dont understand this message, neither how to fix it.

Any help? Thanks





B cannot inhert A because A is private.

Why are we using namespaces? I ask because they aren't very useful if you're working with only one file like you said. They become indespensible if you're building libraries or headers though. Also if you don't use them here, your issues will be easier to fix and explain.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
namespace myns{
	class A{
	public: //declare the constructor public
		A();
		~A();
	};
	class B : public A{
	public:
		B();
	};
}

myns::A::A(){} //constructor of class A in the namespace myns
myns::A::~A(){}
myns::B::B() : myns::A(){}
I'm not having any trouble. Note that the language is case sensitive.
Yes, of course.
Thanks
Topic archived. No new replies allowed.