-1

我有一个使用两个模板类 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(){
...
}
4

1 回答 1

2

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

您需要显式创建一个初始化model.

struct MakeColor {
  MakeColor() : model( /* pass constructor parameters here */ ) {}
  CarType::NewestCar model; // error
};
于 2013-04-19T22:40:01.207 回答