使用相同实数类型的虚拟类型重载函数

时间:2014-04-05 22:33:07

标签: c++ overloading

部首:

using PureCommand = QVector<qint8>;
using PureAnswer = QVector<qint8>;
using CommandName = QString;
using AnswerName = QString;
PureCommand nameToPure(CommandName commandName);
PureAnswer nameToPure(AnswerName answerName);

.cpp的:

PureCommand Hasher::nameToPure(CommandName answerName) {
    return this->commandHash.find(commandName).value();
}

PureAnswer Hasher::nameToPure(AnswerName answerName) {
    return this->answerHash.find(answerName).value();
}

这些给我构建错误:

error: Hasher::nameToPure(AnswerName)' cannot be overloaded
error: with 'PureCommand Hasher::nameToPure(CommandName)'

这些只是一些简单的功能,但我有一些更复杂的...我猜它是因为例如PureCommand和PureAnswer的类型基本相同,但我发现这种方法优雅且易于使用。如果无法完成,我只需要延长功能名称,例如commandNameToPure(CommandName commandName)和answerNameToPure(AnswerName answerName),但我只是想知道这里真正的错误。

0 个答案:

没有答案