Topic: Assignment questions
Author: nico@bredex.UUCP ( BREDEX GmbH)
Date: 2 Sep 91 15:20:03 GMT Raw View
-----
Hi folks,
i have some questions about the assignment operator in C++.
Sorry if they were asked before.
1) See the following code:
class X {
int values[10];
/* no assignment operator defined */
...
};
main()
{
X a, b;
a = b; // What happens to values ?
}
What happens to "values" with "a = b" ?
- illegal (assignment of constant pointer)
- copies all elements of b.values to a.values
- anything else
2) See the following code:
class A {
A& operator= (const A&);
...
};
class B : public A {
B& operator= (const B&);
...
};
class C : public B {
/* no assignment operator defined */
...
};
main()
{
C c1, c2;
...
c1 = c2; // What happens ?
}
What happens with "c1 = c2" ?
- calls A::operator=(), B::operator=() and
a memberwise copy for all NEW components of Class C
- calls only B::operator=() and
a memberwise copy for all NEW components of Class C
- calls only B::operator=()
- does a memberwise copy of ALL componentes of c1
without calling assignments of A and B
- anything else
Please answer direct with a mail to "nico@bredex.uucp".
BTW, are there any FAQs (Frequently Asked Questions)
available ?
aTdHvAaNnKcSe
--------
Nico
address: BREDEX GmbH
email: nico@bredex.uucp Nicolai Josuttis
Kastanienallee 2a
phone: +49 531 75480 D-3300 Braunschweig
fax: +49 531 79635 Germany
--------