什么导致删除功能错误消息?

时间:2013-04-19 22:30:55

标签: c++ templates

我有一个使用两个模板类Trans和Travel的主程序,它会生成编译错误use of deleted function 'MakeColor::MakeColor(),还会生成:note: 'MakeColor::MakeColor()' is implicitly deleted because the default definition would be ill-formed。我怎样才能解决这个问题?

课程旅行:

#include "Trans.hpp"
template<typename A, typename B, typename C>
class Travel {

    public: 

    typedef Trans<A, B> CarType;
    typedef Trans<C, int> BoatType;

    typedef typename CarType::Newest NewestCar;
    typedef typename BoatType::Newest NewestBoat;
};

类Trans:

template<typename A, typename B>
class Trans {

    public: 

    class Newest;
};

主程序:

#include "Travel.hpp"
#include "Trans.hpp"


Travel<MakeColor, MakeMaterial, MakeSize>

struct MakeColor {
  CarType::NewestCar model; // error
};

int main(){
...
}

1 个答案:

答案 0 :(得分:2)

MakeColor没有默认构造函数,因为CarType::NewestCar没有默认构造函数。

您需要显式创建初始化model

的构造函数
struct MakeColor {
  MakeColor() : model( /* pass constructor parameters here */ ) {}
  CarType::NewestCar model; // error
};