所以我有一个以下问题.我有一个类,它是另外两个类的子类,它们都有位置.就像在这个例子中:
struct A
{
float x, y;
std::string name;
void move(float x, float y)
{
this->x += x;
this->y += y;
}
};
struct B
{
float x, y;
int rows, columns;
void move(float x, float y)
{
this->x += x;
this->y += y;
}
};
struct C : public A, public B
{
void move(float x, float y)
{
this->x += x; //generates error: "C::x is ambiguous
this->y += y; //generates error: "C::y is ambiguous
}
};
Run Code Online (Sandbox Code Playgroud)
在代码的后面,我将C类称为A类和B类,当我得到这个位置时,我遇到了问题.我可以以某种方式"组合"两个类的位置变量吗?如果没有,我可以同时更改两个类的位置,或者我必须这样做:
void …Run Code Online (Sandbox Code Playgroud)