2011-07-08 37 views
1

我有一個私人領域的類:更換一組對象與一組新的對象

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

..和一個可選的setter函數:

void setChannelNames(std::set channelNames); 

在setter函數,怎麼辦我使用從setter函數傳遞的那個替換private _channelNames字段?

我想:

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++新手,並期望我應該在這裏做一些指針工作,而不是。

任何快速提示?

謝謝!

+1

應該是'std :: set '而不是普通的'std :: set'嗎? –

+0

哎呀,很好。不能相信我錯過了! – NPike

+1

傳遞參考不是值'const std :: set &',爲了避免值參數的額外副本 –

回答

6

你只需要專門的模板。沒有專業化你不能使用std::set

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