那里。我有类似于下面的代码。
struct SomeClass
{
SomeClass();
};
SomeClass::SomeClass()
{}
template <class K, class T>
struct BaseStruct
{
typedef K kType;
typedef T tType;
kType _key;
tType _element;
BaseStruct();
BaseStruct(kType& key, tType& element);
BaseStruct(BaseStruct&);
};
template <class K,class T>
BaseStruct<K,T>::BaseStruct()
{}
template <class K,class T>
BaseStruct<K,T>::BaseStruct(kType& key, tType& element)
{
_key=key;
_element=element;
}
template <class K,class T>
BaseStruct<K,T>::BaseStruct(BaseStruct& BaseStructInstance)
{
_key=BaseStructInstance._key;
_element=BaseStructInstance._element;
}
struct DerivedStruct:public BaseStruct<int, SomeClass>
{
};
int main(int argc, char *argv[])
{
DerivedStruct derivedStructInstance;
derivedStructInstance=DerivedStruct(0,SomeClass());
}
编译时出现以下错误:
In function `int main(int, char**)':
54 no matching function for call to `DerivedStruct::DerivedStruct(int, SomeClass)'
52 candidates are: DerivedStruct::DerivedStruct()
52 DerivedStruct::DerivedStruct(DerivedStruct&)
Makefile.win [Build Error] [main.o] Error 1
基本上我是说 sctuct 缺少一个复制构造函数,而我通过传递其成员值来初始化结构。此外,我确实有一个复制构造函数。
我该如何解决这个问题?