试图重载类的成员函数,发生了重新声明错误。
在类声明中,甚至Qt都存在问题:
error: class member cannot be redeclared
note: previous declaration is here
此消息是为以下代码中标记为“ overload2”的类提供的:
template <class GraphReaderType, class GraphType>
class GraphsDataset {
public:
template <typename BoostGraphsContainer, typename LabelsContainer>
bool readDataset(const std::string& datasetPath, BoostGraphsContainer& graphsContainer, LabelsContainer& labels) const;
// "Overload 1"
template <typename BoostGraphsContainer, typename LabelsContainer, typename IdsContainer>
bool readDataset(const std::string& datasetPath, BoostGraphsContainer& graphsContainer, LabelsContainer& labels,
IdsContainer& ids) const;
//"Overload 2"
template <typename BoostGraphsContainer, typename LabelsContainer, typename uniqueLabelContainer>
bool readDataset(const std::string& datasetPath, BoostGraphsContainer& graphsContainer, LabelsContainer& labels, uniqueLabelContainer& labelsSet) const;
...
}
编译无法抱怨超载。
GraphsDataset.hpp:120: error: ‘template<class GraphReaderType, class GraphType> template<class BoostGraphsContainer, class LabelsContainer, class uniqueLabelContainer> bool spare::GraphsDataset<GraphReaderType, GraphType>::readDataset(const string&, BoostGraphsContainer&, LabelsContainer&, uniqueLabelContainer&) const’ cannot be overloaded
bool readDataset(const std::string& datasetPath, BoostGraphsContainer& graphsContainer, LabelsContainer& labels, uniqueLabelContainer& labelsSet) const;
^~~~~~~~~~~
如果删除了“过载1/2”成员函数之一,则编译将起作用。
为什么这些功能不能一起重载?