开发者

Replacing a set object with a new set object

I have a class with a private field:

std::set<std::string> _channelNames;

.. and an optional setter function:

void setChannelNames(std::set channelNames);

In the setter function, how do I replace the private _channelNames field with the one passed from the setter function?

I tried:

void Parser::setChannelNames(std::set channelNames) {
    this->_channelNames = channelNames;
}

But this produced an error in VS2005:

Error   2   error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::set' (or there is开发者_如何学JAVA no acceptable conversion)   parser.cpp 61

I am definitely a C++ novice, and expect that I should be doing some pointer work here instead.

Any quick tips?

Thanks!


You just have to specialize template. You cannot use std::set without specialization.

void Parser::setChannelNames(const std::set<std::string> & channelNames) {
    this->_channelNames = channelNames;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜