小编Mul*_*ary的帖子

任何人都可以解释以下 c++ 代码中大括号 () 和大括号 { } 这种奇怪行为背后的机制吗?

详细的阐述有点长,我已经将我面临的问题分解为 3 个“回合”,所以请耐心等待......

对于第一轮,请考虑以下 C++ 代码,该代码没有错误并且行为符合预期:

#include <iostream>
using namespace std;

class rect{
    float width;
    float length;
    
public:
    rect( float w = 5, float l=8 ) : width(w), length(l) {}
    float area(){return width * length;}
};
    
class box{
    rect base;
    float height;
public:
    box(rect a={2,7}, float c=9) : base(a), height(c){ }  //round 1
    //box(rect a={2}, float c=9) : base(a), height(c){ }  //round  2 option 1
    //box(rect a=(2), float c=9) : base(a), height(c){ }  //round 2 option 2
    //box(rect a=(2,7), float …
Run Code Online (Sandbox Code Playgroud)

c++ constructor

0
推荐指数
1
解决办法
82
查看次数

标签 统计

c++ ×1

constructor ×1