虚拟副本构造函数,赋值运算符和多态

时间:2015-07-27 07:56:49

标签: c++ c++11

我正在尝试解决有关赋值运算符的编译错误。

假设我有一个基类:

class A
{
public:
virtual A change_to(const condition& cond){ }
protected:
 double i,j,k;
}

儿童班:

class B : public A
{
public:
A change_to(const condition& cond)
 {
 // do some operations depending on the condition
 return A;
 }
}

class C : public A
{
public:
A change_to(const condition& cond)
 {
 // do some operations depending on the condition
 return A;
 }
}

int main()
{
A elementA;
B elementB;
C elementC;
condition = enum::cond1 ; // assume enumeration is defined

假设我想根据给定条件将元素B更改为C.我想做这样的事情:

elementC=elementB.change_to(condition);  // I need a copy constructor and assignment operator

return 0;
}

如何实现赋值运算符,该运算符考虑到子类族的任何成员之间可以进行更改的事实?

错误在赋值运算符=

0 个答案:

没有答案