Bellow I have some code.
I am trying to use in the child class pointcl the constructor from point. it doesn't work :). ( x is not initialized in the child class object).
Thank you
Bogdan
#include <iostream>
using namespace std;
class point{
int x;
public:
point(int a ){x=a; cout<<"classa point";}
};
class pointcl:public point{
int x,z;
public:
pointcl(int a,int c ):point(a){
z=c;
cout<<x;}
};
You declare another variable "x" in the class pointcl. This will hide the other variable in point. Instead, you can make the int x in class point "protected" and remove the declaration in the subclass:
1 2 3 4 5 6 7 8 9 10
class point{
protected:
int x;
public:
...
};
class pointcl:public point{
int z;
...