Question: Getting error error: 'constexpr' needed for in-class initialization of static data member 'const double Circle::PI' of non-integral type [-fpermissive] for code below. Please help. #include

Getting error error: 'constexpr' needed for in-class initialization of static data member 'const double Circle::PI' of non-integral type [-fpermissive] for code below. Please help.

#include "circle.h"

#include "square.h"

#include

#include

#include

using namespace std;

int main()

{

char type;

while(true)

{

cout << "Enter type of figure(C - Circle, S - Square or Q - quit: "; cin >> type;

if(type == 'C')

{

Circle* c = new Circle;

c->input();

c->print();

delete c;

}

else if(type == 'S')

{

Square* s = new Square;

s->input();

s->print();

delete s;

}

else if(type == 'Q')

exit(0);

else

cout << "Invalid ";

cout << endl;

}

}

circle.h

#ifndef CIRCLE_H

#define CIRCLE_H

#include

class Circle

{

double radius;

//constexpr static const double PI = 3.14;

static const double PI = 3.14;

public:

Circle(double r = .0);

void print() const;

double area() const;

void input();

};

#endif // CIRCLE_H

Square.H

#ifndef SQUARE_H_INCLUDED

#define SQUARE_H_INCLUDED

#include

class Square

{

private:

double a;

double b;

public:

Square(double _a = 0.0, double _b = 0.0);

void print() const;

double area() const;

void input();

};

#endif // SQUARE_H_INCLUDED

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!