【发布时间】:2012-04-16 09:00:06
【问题描述】:
啊。
template <typename T>
class A
{
public:
int a;
}
b.h
template <typename T>
class B : public A<T>
{
public:
int f();
}
template <typename T>
int B<T>::f()
{
int t;
t = this->a; //Okay
t = a //Error
return 0;
}
为什么我不使用this->时会出现错误?
我可以用某种方法省略this->吗?
(我修正了一些错误)
【问题讨论】:
-
Joachim Pileborg 给了你答案。除此之外,提供的代码还存在其他问题,无法编译。
-
这是实际代码吗?类定义后没有尾随分号,
int B<T>:f()的范围运算符不正确,并且错误行中没有分号。 -
哦,这只是打字错误。我修好了。
标签: c++ templates inheritance