如何更改有关C ++ Template类的代码以使其完成? [英] How do I change the code about C++ Template class to make it through?

查看:78
本文介绍了如何更改有关C ++ Template类的代码以使其完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//代码



//Code

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;
};







//编制报告

警告C4346:ModelCalc< vector> :: vector_type:




//compiling report
warning C4346: "ModelCalc<vector>::vector_type":

error C2143: syntax error : missing";"(in front of"&")
error C4430: 

推荐答案

你应该使用 typename 来获取 ModelCalc< vector> :: vector_type< / vector> ,因为这是不是类型。



You should use typename for ModelCalc<vector>::vector_type</vector>, since this is not a type.

template <class vector="">
const typename ModelCalc<vector>::vector_type& ModelCalc<vector>::distances() const
{
   return m_distances;
};

template <class vector="">
const typename ModelCalc<vector>::value_type& ModelCalc<vector>::length() const
{
   return m_length;
};</vector></vector></class></vector></vector></class>

这篇关于如何更改有关C ++ Template类的代码以使其完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆