Say I have a base class A and a derived class B that adds some extra members. Now I'd like to have a setter function for class B that acceses it's own members directly but assigns the derived members in batch using a temporary A object. Here's some example code:
class A
{
public:
int x;
int y;
A(int arg1, int arg2)
: x(arg1), y(arg2) {}
};
class B : public A
{
public:
int z;
B(int arg1, int arg2, int arg3)
: A(arg1, arg2), z(arg3) {}
void setB(int arg1, int arg2, int arg3) {
/*something here*/ = A(arg1, arg2);
this->z = arg3;
}
};
//edit
I guess I wasn't clear that the question isn't really "Can I?" but rather "How can I?". To be even more specific: What can I put in place of /*something here*/
to make setB() actually work the same as:
void setB(int arg1, int arg2, int arg3) {
this->x = arg1;
this->y = arg2;
this->z = arg3; }