#include <iostream>
class Character
{
private:
short x = -1;
short y = -1;
};
class Luchnik : public Character
{
public:
Luchnik(short x, short y) {
this->x = x;
this->y = y;
}
private:
short x = 0;
short y = 0;
};
int main() {
Luchnik *l = new Luchnik(1, 2);
Character a();
&a = l;
delete l;
return 0;
}
visual stuido 写入表达式必须有效才能更改左侧值。
这是屏幕截图
更新
或者您可以在 Luchnik 构造函数中获取一个向量指针并将 vector[x][y] 对象更改为 Luchnil
我是这样写的,但是不行,看不懂指针和类的东西
Luchnik(short x, short y, std::vector<std::vector<Character>> map) {
this->x = x;
this->y = y;
Character* pm = &(map[x][y]);
pm = *this;
}
int main() {
std::vector<std::vector<Character>> board = new std::vector<std::vector<Character>>(3, std::vector<Character>(4));
Luchnik l(1, 2, *board);
return 0;
}