我有一个带有私有(private)字段的类:
std::set<std::string> _channelNames;
.. 和一个可选的 setter 函数:
void setChannelNames(std::set channelNames);
在 setter 函数中,如何将私有(private) _channelNames 字段替换为从 setter 函数传递的字段?
我试过:
void Parser::setChannelNames(std::set channelNames) {
this->_channelNames = channelNames;
}
但这在 VS2005 中产生了一个错误:
Error 2 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::set' (or there is no acceptable conversion) parser.cpp 61
我绝对是一个 C++ 新手,我希望我应该在这里做一些指针工作。
有什么快速提示吗?
谢谢!
最佳答案
你只需要专门化模板。您不能在没有专门化的情况下使用 std::set
。
void Parser::setChannelNames(const std::set<std::string> & channelNames) {
this->_channelNames = channelNames;
}
关于c++ - 用新的集合对象替换集合对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6628522/