c***d 发帖数: 996 | 1 ☆─────────────────────────────────────☆
matII (当归) 于 (Sun Aug 20 16:34:54 2006) 提到:
测试程序如下,不知为何编译器报错不能access x,
同样的code, 把templates都换成具体的int,就没有问题。
哪里写错了呢?
btw, 我用的编译器是gcc 4.0.1
#include
using namespace std;
template
class A
{
protected:
T x;
};
template
class B:public A
{
public:
T f(const T& y){x=y;return x;};
};
int main(void)
{
B b;
cout<
}
test.cpp: In member function 'T B::f(const T&)':
test.cpp:15 | c********x 发帖数: 84 | 2
Holy cow, you guys are so dumb, the problem is x is not define in the
function,
here is the correct one:
T f(const T& y){ T x; x=y;return B::x;};
just add the definition "T x;"
【在 c***d 的大作中提到】 : ☆─────────────────────────────────────☆ : matII (当归) 于 (Sun Aug 20 16:34:54 2006) 提到: : 测试程序如下,不知为何编译器报错不能access x, : 同样的code, 把templates都换成具体的int,就没有问题。 : 哪里写错了呢? : btw, 我用的编译器是gcc 4.0.1 : #include : using namespace std; : template : class A
| r****r 发帖数: 115 | 3 真不知道谁dumb啊
你要是天天来,这个版不如关了算了
【在 c********x 的大作中提到】 : : Holy cow, you guys are so dumb, the problem is x is not define in the : function, : here is the correct one: : T f(const T& y){ T x; x=y;return B::x;}; : just add the definition "T x;"
|
|