我有一个使用两个模板类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(){
...
}
答案 0 :(得分:2)
MakeColor
没有默认构造函数,因为CarType::NewestCar
没有默认构造函数。
您需要显式创建初始化model
。
struct MakeColor {
MakeColor() : model( /* pass constructor parameters here */ ) {}
CarType::NewestCar model; // error
};