是否可以自动生成这样的内容?我只想要特定成员一次并生成三个类(它们相似但是......)
class recipe{
public:
int timeToPrepare;
std::string name;
}
class recipeQuery{
public:
baseQuery<int> timeToPrepare;
baseQuery<std::string> name;
}
class recipeScheme{
public:
schemeItem<int> timeToPrepare;
schemeItem<std::string> name;
}
答案 0 :(得分:5)
这样的东西?
template <class T1 = int, class T2 = std::string> class recipe {
T1 timeToPrepare;
T2 name;
};
typedef recipe< baseQuery<int>, baseQuery<std::string> > recipeQuery;
typedef recipe< schemeItem<int>, schemeItem<std::string> > recipeQuery;
答案 1 :(得分:0)
template<template<typename> class T>
class recipe{
public:
T<int> timeToPrepare;
T<std::string> name;
};
typedef recipe<baseQuery> recipeQuery;
typedef recipe<schemeItem> recipeScheme;