我正在用 C++ 为一个类(学校,而不是代码)编写一个简单的类。我有一点 C++ 经验,但是已经有一段时间了,所以我正在重新学习我忘记的东西并学习了很多新语法(我在 Java 方面有更多经验)。这是代码:
#include <iostream>
#include <string>
using namespace std;
class Project112
{
private:
string romanNumeral;
int decimalForm;
public:
Project112()
{
romanNumeral = "";
decimalForm = 0;
}
int getDecimal()
{
return decimalForm;
}
};
这是驱动程序:
include cstdlib
include <iostream>
using namespace std;
int main()
{
Project112 x;
int value2 = x.getDecimal();
return 0;
}
这是一个更大程序的一部分,但我已将其简化为这一点,因为这就是问题所在。每次我尝试运行该程序时,都会出现以下错误:
main.cpp:10: error: 'Project112' was not declared in this scope
main.cpp:10: error: expected `;' before 'x'
main.cpp:14: error: 'x' was not declared in this scope
有人可以解释这个问题吗?提前致谢。