我有一个配置类,我想传递给另一个类(称为使用)在构造函数中。我想将配置类作为私有成员变量存储在Use类中。我希望它是const。如何传递一个const对象
到目前为止,我有这样的代码:
class Configuration{
private:
int value1_;
public:
Configuration();
Configuration(int value1){value1_=value1;}
int value1() const {
return value1_;
}
};
class Use{
private:
//const me
Configuration config_;
int something_;
public:
Use(Configuration &config){
config_=config;
}
void doSomething(){
something_+=config_.value1();
}
};
我想为const Use::config_
,但每当我试图在混乱的编译错误结束的方式。我该怎么做?
什么编译错误? – 2012-07-06 17:23:59