Reputation: 150
Attempting to overload a member function of a class, a redeclaration error occurred.
In class declarations even Qt reveal a problem:
error: class member cannot be redeclared
note: previous declaration is here
This message is provided for the classes marked as "overload2" in the code below:
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;
...
}
The compilation fails complaining about overloading.
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;
^~~~~~~~~~~
The compilation works if one among "Overload 1/2" member function is deleted.
Why these functions can't be overloaded together?
Upvotes: 0
Views: 2219