Hi,

How can we able to access Base class Copy Constructor while calling Derived
class Copy Constructor? Or How can we access Base Class Assignment Operator
while calling Derived Class Assignment Operator? Any suggestions?

Regards,

Abi Gabriel

Code Snippet:
-------------

class Base
{
public :
Base(int lx = 10, int ly = 11) : x(lx), y(ly)
{

}

Base(const Base & rhs) // Copy constructor
{
x = rhs.x;
y = rhs.y;
}

operator = (const Base & rhs) // Assignment Operator
{
x = rhs.x;
y = rhs.y;
}

void setX(int lX) { x = lX; }
void setY(int lY) { y = lY; }

int getX() const { return x; }
int getY() const { return y; }

private :
int x;
int y;
};

class Derived : public Base
{
public :
Derived(int la = 12, int lb = 13) : a(la), b(lb), Base(la + 5, lb - 5)
{

}

Derived(const Derived & rhs) // Copy constructor
{
setX(rhs.getX()); // Explicit setting of
setY(rhs.getY()); // Base Class parameters

a = rhs.a;
b = rhs.b;
}

operator=(const Derived & rhs) // Assignment Operator
{
setX(rhs.getX()); // Explicit setting of
setY(rhs.getY()); // Base Class parameters

a = rhs.a;
b = rhs.b;
}

void setA(int lA) { a = lA; }
void setB(int lB) { b = lB; }

private :
int a;
int b;
};

void main()
{
Derived d1, d2;

d1.setX(21);
d1.setY(22);
d1.setA(23);
d1.setB(24);


// It will call only Assignment Operator of Derived Class alone,
// not of Base Class, because of this the Base Class members
// won't be set properly. Hence, to set the parameters properly
// in Base Class, we need to call explicit set() member functions
// of Base Class in the Derived Class Assignment Operator , Abi
// Is there any way to avoid this explicit setting in Derived Class?

d2 = d1;

// It will call only Copy Constructor of Derived Class alone,
// not of Base Class, because of this Base Class members won't
// be set properly. Hence, to set the parameters properly in
// Base Class, we need to call explicit set() member functions
// of Base Class in the Derived Class Copy Constructor, Abi
// Is there any way to avoid this explicit setting in Derived Class?

Derived d3 = d1;

}