一个模板类继承的问题。。。。
以下代码在GNU G++中报
test.cpp:53: 错误:依赖名 ‘CAttrValue <TVal> ::CAttrValue’ 被解析为非类型,但实例化却产生了一个类型
test.cpp:53: 附注:如果您想指定类型,请使用 ‘typename CValue <TVal> ::CValue’
请问我哪里写错了??我用typename CAttrValue <TVal> ::CAttrValue()结果是不被执行的。
#include <iostream>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef unsigned short WORD;
template <typename TVal>
struct CValue
{
CValue()
{
base = 0;
extend = 0;
attach = 0;
rate = 100;
value = 0;
}
CValue(TVal b,TVal e,TVal a,WORD r)
{
base = b;
extend = e;
attach = a;
rate = r;
}
TVal base;
TVal extend;
TVal attach;
WORD rate;
TVal value;
};
template <typename TVal>
struct CMaxValue : CValue <TVal>
{
CMaxValue()
{
current=0;
CValue <TVal> ::CValue <TVal> ();
}
CMaxValue(TVal b,TVal e,TVal a,WORD r,TVal c)
{
current=c;
CValue <TVal> ::CValue(b,e,a,r);
}
TVal current;
};
int main()
{
CMaxValue <long> =CMaxValue <long> (1,2,3,4,5);
//CMaxValue <long> ;
cout < <.base < <endl;
}
[解决办法]
兄弟,你怎么基础的派生类构造函数调基类构造函数的语法还没会,就已经跳到了从模板进行派生?
CMaxValue(): CValue <TVal> (), current(0)
{
}