1
你好我有一个小问题,我的C++项目C++,投构造,“没有运营商‘=’匹配这些操作数
首先,我得到了类:
class base
{
protected:
int R, G, B;
public:
base();
~base();
};
和第二类:
class superBase :
public base
{
public:
superBase(){R=0; G=0; B=0};
~superBase();
};
和含有碱class'es的矩阵中的最后类:
class gameTable : public gameGraphics
{
private:
base** table;
public:
gameTable();
~gameTable();
}
当我构建gameTable类别i构造64个基础对象与RANDOM R,G,B值从0到255
因此,当节目的推移,一些在表矿elemntes“演变”和变得超强碱的。所以这里是我的问题,我不知道该怎么做。我试过这个,
这似乎无法正常工作。
superBase newBase;
table[column][row].~base();
table[column][row] = newBase;
和其他版本:
table[column][row].~base();
table[column][row] = new superBase;
我的问题是如何对表格的一个元素演变为超强类元素。据我所知,它可以使用与基类元素相同的指针。
问候和感谢您的帮助!
“table”的定义在哪里? – Soren
'new T'返回一个指针。你的“2D数组”不包含指针。另外,不要这样调用析构函数。 – juanchopanza
'table [column] [row]。〜base();'< - 不要调用这样的析构函数。如果你用'new'分配,你需要'删除'。但是你应该尽可能使用智能指针和向量。 – crashmstr