圆周类认为操作是指针

时间:2017-03-18 03:56:11

标签: c++ pointers math

简单的程序,但我收到错误说:

" Circle :: getCircumference:非标准语法;使用'&'创建指向成员的指针。"

我想要一个字符串指针来设置每个圆圈的名称。任何帮助表示赞赏!

#include <iostream>
#include <cstring>

using namespace std;

class Circle
{
private:
double pi = 3.14;
double radius;

public:

void setRadius(double r)
{
    radius = r;
}

double getRadius()
{
    return radius;
}

double getArea()
{
    return pi* radius * radius;
}

double getCircumference()
{
    return 2 * pi * radius;
}
};

int main()
{
Circle circle1;
Circle circle2;
double circRad1;
double circRad2;

cout << "Enter the radius for cirle 1: ";
cin >> circRad1;

cout << "Enter the radius for cirle 2: ";
cin >> circRad2;

circle1.setRadius(circRad1);
circle2.setRadius(circRad2);

cout << "Circle 1 radius: " << circle1.getRadius() << "\n";
cout << "Circle 1 area: " << circle1.getArea() << "\n";
cout << "Circle 1 circumfrence: " << circle1.getCircumference << "\n";
cout << "\n";

cout << "Circle 2 radius: " << circle2.getRadius() << "\n";
cout << "Circle 2 area: " << circle2.getArea() << "\n";
cout << "Circle 2 circumfrence: " << circle2.getCircumference << "\n";

return 0;
}

0 个答案:

没有答案