c++ - 用新的集合对象替换集合对象

标签 c++

我有一个带有私有(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/

相关文章:

c++ - std::map 枚举的默认值

c++ - 并发/多线程:是否可以通过这种方式生成相同的输出?

c++ - 编译 C++ 代码时出现链接器错误

c++ - 内存位置作为放大动态数组中的最后一个值

c++ - qt 从 QChart 获取子项(标注)

c++ - 无法将子类 ... 转换为其私有(private)基类

c++ - 使用 fft 的高斯模糊

c++ - Netbeans/C++ : Link 2 projects together (Executable/Dynamic Library)

c++ - 如何将 GL_RED 格式转换为 GL_RGBA 格式

c++ - 在消息框内有一个组合框