class Test {
bool isVal() const {
return isVal;
}
private:
bool isVal;
};
Run Code Online (Sandbox Code Playgroud)
在编译这个文件时,它说
testClass.cpp:9:`bool Test :: isVal'的声明
testClass.cpp:3:与之前的声明`bool Test :: isVal()'冲突
虽然这同样适用于java
class Test {
private boolean isVal;
public boolean isVal() {
return isVal;
}
}
Run Code Online (Sandbox Code Playgroud)
不知道为什么C++无法解决这个问题.
我发现了一个想要尝试的begginers c ++挑战.但是,下面的代码说它在编译时包含错误.如果我一次尝试一行,它会在最后的第一个类定义中退出...我不知道什么是错的:)
#include <iostream>
using namespace std;
class Polynomial {
int a, b, c, functionValue;
public:
Polynomial (int, int, int);
static void functionValue(Polynomial);
};
Polynomial::Polynomial (int x, int y, int z) {
a = x;
b = y;
c = z;
}
void Polynomial::functionValue(Polynomial x) {
for (int i = 0; i < 5; i++) {
x.functionValue = x.a * pow(i, 2) + x.b * i + x.c;
cout << "The value of the function for x = " …Run Code Online (Sandbox Code Playgroud)