Heres the code:
#include
#include
using namespace std;
class classA
{
protected:
v
You forgot to declare the constructor in the class definition. Declare it in public
section of the class (if you want clients to create instance using it):
class classA
{
public:
classA(); // you forgot this!
protected:
void setX(int a);
private:
int p;
};
Now you can write its definition outside the class which you've already done.
An empty constructor is provided by default: this is correct. But if you redefine it, it's not a default constructor any more. You have to declare and define it. If you only declare it (without the body), it's incorrect: you have to define it as well. If you define it without a declaration in the class, it's an error as well. You can though, "combine" declaration and definition by writing as follows:
class classA
{
// ....
public:
classA() { p = 0;}
};
or in this case even better:
class classA
{
// ....
public:
classA():p(0) {}
};
class classA
{
protected:
classA(); // you were missing an explicit declaration!
void setX(int a);
private:
int p;
};
classA:: classA()
{
p = 0;
}
classA
has no member named classA()
to implement.
class classA
{
// ....
public:
classA() ; // Missing the declaration of the default constructor.
};