由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - [合集] 关于template和inheritance的问题请教
相关主题
一个关于C++ template和overload的问题请教一下这个template function在gcc下要怎么修改
[合集] 怎样有效的传递C静态数组的变量名?C++ template function type
问一个简单的C++问题a c++ question for template
namespace 问题一个C++ template的问题
编译器如何分辨返回类型不同的函数?C++ Q96: function inheritance (转载)
私有成员不能用类成员函数修改?a simple question for C++ class
还有一个问题请问一个exception题目
C++ Q04: template member两个继承问题
相关话题的讨论汇总
话题: template话题: class话题: const话题: int
进入Programming版参与讨论
1 (共1页)
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;"

1 (共1页)
进入Programming版参与讨论
相关主题
两个继承问题编译器如何分辨返回类型不同的函数?
为什么我看不懂下面的code,是不是水平还不够?私有成员不能用类成员函数修改?
C++疑问还有一个问题
two c++ interview questions! (转载)C++ Q04: template member
一个关于C++ template和overload的问题请教一下这个template function在gcc下要怎么修改
[合集] 怎样有效的传递C静态数组的变量名?C++ template function type
问一个简单的C++问题a c++ question for template
namespace 问题一个C++ template的问题
相关话题的讨论汇总
话题: template话题: class话题: const话题: int