【问题标题】:argument convert in class类中的参数转换
【发布时间】:2015-07-19 02:26:47
【问题描述】:

我有以下代码:

    template<class TDataType> class PassData
{
public:

    PassData(int Id,
        const Kratos::Variable<TDataType>& rVariable,
        const TDataType& Value) : mId(Id),
        mVariable(rVariable),
        mValue(Value){}
    void SetProperties()
    {
        mpModeler->SetProperties(mId, mVariable, mValue);
    }
    int mId;
    Kratos::Variable<TDataType> mVariable;
    TDataType mValue;
};

...

        template<class TDataType>
        void SetProperties(IndexType PropertiesId,
            const Variable<TDataType>& rVariable,
            double* value,int size)
        {
            std::vector<double> v;
            for (int i = 0; i < size; i++)v.push_back(value[i]);
            PassData<std::vector<double>> S = PassData<std::vector<double>>(PropertiesId, rVariable,v);
            S.SetProperties();
        }

编译时出现如下错误:

Error   7   error C2665: 'Kratos::PassData<std::vector<double,std::allocator<_Ty>>>::PassData' : none of the 2 overloads could convert all the argument types   
Error   8   error C2512: 'Kratos::PassData<std::vector<double,std::allocator<_Ty>>>' : no appropriate default constructor available

谁能帮我看看?

谢谢,

唐老鸭

【问题讨论】:

    标签: c++ constructor arguments converter


    【解决方案1】:

    你有构造函数

    PassData(int Id, const Kratos::Variable<TDataType>& rVariable, const DataType& Value)
    

    然后你像这样创建你的 PassData 对象

    PassData<std::vector<double>>(PropertiesId, rVariable,v); 
    

    其中 PropertiesId 的类型为 IndexType (?)

    rVariable 是 const Variable& 类型(没关系)

    v 的类型是 std::vector (?)

    【讨论】:

    • 感谢您的热情回复。是的。我发现如果构造函数是 PassData(const DataType& Value) 并像这样创建 PassData 对象 PassData<:vector>>(v);对象创建没问题。
    • 谁能帮我看看这个问题?谢谢
    • 即使我将'IndexType PropertiesId'更改为'int PropertiesId',错误仍然相同,谁能帮我看看问题?谢谢
    猜你喜欢
    • 1970-01-01
    • 2015-05-19
    • 1970-01-01
    • 2015-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多