Say I have a class Item which overloads the assignment operator if I make a class called weapon that publicly inherits the Item class can I use the operator to assign a weapon to a item?
like this?
Code:
Class Item
{
public:
void SetAB(int, int);
Item& operator = (const Item& i);
private:
int a;
int b;
};
Item& Item::operator = (const Item& i)
{
a = i.a;
b = i.b;
return *this;
}
void Item::SetAB(int A,int B)
{
a = A;
b = B;
}
Class Weapon : public Item
{
public:
//doesnt matter i dont overload the = again
private:
int c;
int d;
};
int main()
{
Weapon sword;
sword.SetAB(1 , 2);
Item temp;
temp = sword;
return 0;
}
Now my question is will temp.a and temp.b hold sword.a and sword.b and if I did it the other way sword = temp would sword hold temp.a and temp.b in sword.a and sword.b?
Also is this something thats not violating any standards of programming? Like void main() or something i mean if it works but its just bad practace.