1
我想擁有一個可以存儲各種對象的通用存儲類,我不想使用存儲所有對象的異構容器類。我想創建一個模板存儲類,並創建一個繼承一般的存儲類從這種與不同類型的元類:從模板類的多重繼承
template<typename Type>
struct SingleInterface
{
public:
SingleInterface() = default;
virtual ~SingleInterface() = default;
SingleInterface(const SingleInterface &) = default;
SingleInterface & operator=(const SingleInterface &) = default;
SingleInterface(SingleInterface &&) = default;
SingleInterface & operator=(SingleInterface &&) = default;
void get(const std::string & keyword, Type * ptr)
{
// implementation
}
};
我的一般類,如下:
class MutliInterface: public SingleInterface<double>, SingleInterface<int>
{
public:
MutliInterface() = default;
virtual ~MutliInterface() = default;
};
當我創建一個MutliInterface類,我得到以下錯誤:
MutliInterface interface;
double *v;
interface.get("test", v);
'get' is ambiguous '
未輸入get方法解決歧義??? void get(const std :: string&keyword,Type * ptr) – apramc