<分区>
所以我有一些简单的问题/结构:
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:我才意识到错误实际上只在这里出现(here 链接到代码):
#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() {}
很明显我把模板搞砸了。抱歉,没有把它写在第一位。