首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++模板使用有关问题

2014-01-14 
C++模板使用问题求助using namespace stdtemplate class VECTORclass ModelCalc{public:typedef VECTOR

C++模板使用问题求助
using namespace std;

template <class VECTOR>
class ModelCalc
{
public:
typedef VECTOR                   vector_type;
typedef typename vector_type::value_type  value_type;

public:
ModelCalc(const vector_type& xValues,
const vector_type& distances,
const value_type&   length
);
const vector_type& distances() const;
const value_type& length() const;

private:
vector_type m_xValues;
vector_type m_distances;
value_type  m_length;
};

template <class VECTOR>
ModelCalc<VECTOR>::ModelCalc(const vector_type& xValues,
 const vector_type& distances,
 const value_type& length
 ):
m_xValues(xValues),
m_distances(distances),
m_length(length)
{
};

template <class VECTOR>
const ModelCalc<VECTOR>::vector_type& ModelCalc<VECTOR>::distances() const
{
return m_distances;
};

template <class VECTOR>
const ModelCalc<VECTOR>::value_type& ModelCalc<VECTOR>::length() const
{
return m_length;
};


//编译报信

warning C4346: “ModelCalc<VECTOR>::vector_type”: 依赖名称不是类型  用“typename”为前缀来表示类型
error C2143: 语法错误 : 缺少“;”(在“&”的前面)
error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int

觉得语法没有问题啊,怎么通过不了呢

[解决办法]
最好把代码贴全,放到代码格式化里,方便他人复制编译。
[解决办法]
在模板作为参数时用typename,用class 是无法代替的。

热点排行