所以我有一些简单的问题/结构:
class Class1 {
public:
Class1() {};
~Class1() {};
protected:
std::string name;
}
class Class2 : public Class1
{
public:
Class2() : number(id_generator++) {
name = "My-name"; // (1) want to access field inherited from Parent
};
private:
const unsigned int number;
static unsigned int id_generator;
}
编译器抱怨 (1): 'name' was not declared in this scope
。怎么了?它看起来很简单,但我看不到它。
EDIT1:只是我意识到错误实际上只在这里发音(这里链接到代码):
#include <string>
template<int dim>
class Class1 {
public:
Class1() {};
~Class1() {};
protected:
std::string name;
};
template<int dim>
class Class2 : public Class1<dim>
{
public:
Class2() : number(id_generator++) {
name = "My-name"; // (1) want to access field inherited from Parent
};
private:
const unsigned int number;
static unsigned int id_generator;
};
int main() {}
所以显然我把模板弄乱了。对不起,没有把它写在第一位。