NPike
NPike

Reputation: 13254

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 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!

Upvotes: 1

Views: 244

Answers (1)

user405725
user405725

Reputation:

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;
}

Upvotes: 6

Related Questions