65,187
社区成员




class Object
{
private:
int value;
public:
Object(int i):value(i)
{
}
const Object& operator=(const Object& obj)
{
value = obj.value;
return *this;
}
const Object& operator=(const int i)
{
value = i;
return *this;
}
int getValue(void) const
{
return value;
}
static void Test(void)
{
Object a(1),b(2),c(3);
Widget x(1), y(2), z(3);
a = b = c = 4;
//((a=b)=c)=4; // Error 2 error C2678: binary '=' :/
no operator found which takes a left-hand operand of type 'const Object' /
(or there is no acceptable conversion)
}
const Object& operator=(const int i)
{
value = i;
return *this;
}
class Base
{private:
int Y;
public:
Base(int y=0) {Y=y;cout<<"Base("<<y<<")\n";}
~Base() {cout<<"~Base()\n";}
void print() {cout <<Y<< "";}
};
class Derived:public Base
{
private:
int Z;
public:
Derived(int y, int z):Base(y)
{
Z=z;
cout<<"Derived("<<y<<","<<z<<")\n";
}
~Derived() {cout<<"~Derived()\n";}
void print()
{
Base::print();
cout<<Z<<endl;
}
};
void main()
{Derived d(10,20);
d.print();
}
为什么不输出Base(0);