1
我宣布operator=
这样的:C++类模板拷贝构造器的返回类型
HashTable& operator=(const HashTable& aTable);
而且我定义它的类以外的方式如下:
template <typename HashElement>
HashTable& HashTable<HashElement>::operator=(const HashTable& aTable)
{
/*Do the copy thing*/
return *this;
}
我期望它用下面的代码编译:
HashTable<EngWord> hashTable;
HashTable<EngWord> hashTableA;
hashTableA = hashTable;
但是编译器不喜欢de的签名FINITION。错误信息是:
HashTable: suer of class template requires template argument list
HashTable<HashElement>::operation=': unable to match function definition or an existing declaration
我在网上看到的应该是我写的。怎么了?
另一种选择是使用尾随返回类型 –