delegating constructors are permitted only in C++11 error in M1 vscode

55 Views Asked by At

I have a problem with delegating constructors in M1 vscode.

// Rectangle.cpp
#include <iostream>
using namespace std;

#include "Rectangle.h"

Rectangle::Rectangle() : Rectangle(1, 1) {}

Rectangle::Rectangle(int len) : Rectangle(len, len) {}

Rectangle::Rectangle(int w, int h) {
    width = w;
    height = h;
}

double Rectangle::getArea() {
    return width * height;
}
// main.cpp
#include <iostream>
using namespace std;

#include "Rectangle.h"

int main() {
    Rectangle rect1;
    Rectangle rect2(13);
    Rectangle rect3(5, 8);

    cout << "rect1: " << rect1.getArea() << endl;
    cout << "rect2: " << rect2.getArea() << endl;
    cout << "rect2: " << rect3.getArea() << endl;

    return 0;
}
//Rectangle.h
class Rectangle {
    int width;
    int height;
public:
    Rectangle();
    Rectangle(int len);
    Rectangle(int, int);
    double getArea();
};
(base) -@MacBook-Air-of-- - % g++ Rectangle.cpp main.cpp -o rectangle2.out
Rectangle.cpp:6:26: error: delegating constructors are permitted only in C++11
Rectangle::Rectangle() : Rectangle(1, 1) {}
                         ^~~~~~~~~
Rectangle.cpp:8:33: error: delegating constructors are permitted only in C++11
Rectangle::Rectangle(int len) : Rectangle(len, len) {}
                                ^~~~~~~~~
2 errors generated.

These are my source codes and my version is C++17 and I'm using code-runner. When I build one code, it works but When I separate codes, it doesn't. I want to know that I could delegating constructors with no other options. Thank you

0

There are 0 best solutions below