有如下程序: #include using namespace std; class Cup{ public: Cup(double val=5.8):price(val) {

admin2021-07-02  14

问题 有如下程序:
       #include
       using namespace std;
       class Cup{
       public:
           Cup(double val=5.8):price(val) { }
           void SetPrice(double val) { price=val; }
           double GetPrice() const { return price;}
       private:
           double price;
       };
       int main(){
           const Cup c1(4.5);
           Cup c2(29.8);
           c1.SetPrice(5.8);        //①
           c2.SetPrice(12.8);       //②
           c1.GetPrice();           //③
           c2.GetPrice();           //④
           return 0;
       }      
在标注号码的语句行中存在语法错误的是

选项 A、①
B、②
C、③
D、④

答案A

解析 本题考查常对象,常对象只能引用常成员函数,不能引用非常成员函数,所以①是错误的。答案为A选项。
转载请注明原文地址:https://kaotiyun.com/show/I4fp777K
0

最新回复(0)