我有一个配置类,我想在构造函数中传递给另一个类(称为 Use)。我想将配置类存储在 Use 类中作为私有成员变量。我希望它是常量。
到目前为止,我有这个代码:
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_
,但我尝试的每一种方式都以令人困惑的编译错误告终。我该怎么做?