我正在尝试声明一个名为 BASE
的基类,但我在使用继承类型 A
和 B
时遇到了问题BASE
类。我遇到了错误
|In member function 'NODE& NODE::operator=(const NODE&)':|
16|warning: no return statement in function returning non-void|
In member function 'void BASE<T, SIZE>::init_A(int) [with T = NODE, unsigned int SIZE = 2u]':|
96|instantiated from here|
39|error: no match for 'operator=' in 'A<NODE, 2u>::DATA[index] = a'|
13|note: candidates are: NODE& NODE::operator=(const NODE&)|
#include <iostream>
class NODE
{
private:
public:
NODE(){}
~NODE(){}
};
template <class T, size_t SIZE>
class A;
template <class T, size_t SIZE>
class BASE
{
protected:
static T DATA[SIZE];
public:
BASE()
{
}
~BASE(){}
void init_A(int index)
{
A<T,SIZE>::DATA[index] = T();
}
};
template <class T, size_t SIZE>
class A : public BASE<T,SIZE>
{
protected:
public:
A(){}
~A(){}
};
template <class T, size_t SIZE>
T BASE<T,SIZE>::DATA[SIZE] = {};
int main()
{
BASE<NODE,2> base;
base.init_A(0);
return 0;
}
最佳答案
我可以编译它,但它可能无法满足您的要求。 第一个问题是你的赋值运算符 promise 返回一些东西但没有:
NODE& NODE::operator=(const NODE&)
{
}
试试这个
NODE& NODE::operator=(const NODE&)
{
return *this;
}
第二个问题是
A<T,SIZE> a;
A<T,SIZE>::DATA[index] = a;
DATA
是 T
的数组,不是 A<T,SIZE>
.
试试这个
A<T,SIZE>::DATA[index] = T();
最后你需要在某处声明你的静力学。 罢工>
最后,您需要在某处定义您的静力学。参见 here
关于c++ - error : no match for 'operator=' . 尝试从基类继承并从基类初始化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17964506/