代码如下,我用的IDE是codeblock,在vs中编译没问题,到我这就各种问题,请大神帮忙看看,谢谢
- #include<iostream>
- using namespace std;
- class circle
- {
- public:
-
- double r;
-
- double pi = 3.1415926;
- double area = pi*r*r;
-
- };
- int main()
- {
- circle pi;
- cout << "请输入area" << endl;
- cin >> pi.r;
-
- cout << pi.area << endl;
-
- system("pause");
- return 0;
- }
一直在出错, build log如下:
- .cpp|34|error: ISO C++ forbids initialization of member 'pi'|
- .cpp|34|error: making 'pi' static|
- .cpp|34|error: ISO C++ forbids in-class initialization of non-const static member 'pi'|
- .cpp|35|error: 'circle::pi' cannot appear in a constant-expression|
- .cpp|35|error: 'circle::r' cannot appear in a constant-expression|
- .cpp|35|error: 'circle::r' cannot appear in a constant-expression|
- .cpp|35|error: ISO C++ forbids initialization of member 'area'|
- .cpp|35|error: making 'area' static|
- .cpp|35|error: ISO C++ forbids in-class initialization of non-const static member 'area'|
- .cpp||In function 'int main()':|
- .cpp|46|error: 'system' was not declared in this scope|
- ||=== Build finished: 10 errors, 0 warnings ===|
请帮忙看看,谢谢