是什么导致删除函数错误消息



我有一个主程序,它使用了两个模板类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;
};

类反式:

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(){
...
}

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

你需要显式地创建一个构造函数来初始化model

struct MakeColor {
  MakeColor() : model( /* pass constructor parameters here */ ) {}
  CarType::NewestCar model; // error
};

相关内容

最新更新