作为一名初级程序员,我正在学习 C++ 编程的基础知识,包括头文件的创建。我正在关注教授在 Youtube 上的讲座,并重新创建了相同的代码结构来存储下面的类整数。我收到以下类行的编译错误消息。
错误(活动)E0147 声明与“int MyInteger::get() const”不兼容
#include<iostream>
class MyInteger
{
private:
int i;
public:
void set(int);
int get() const;
};
void MyInteger::set(int a)
{
i = a;
}
void MyInteger::get() const
{
return i;
};
int main() {
std::cout << "Hello, world!\n";
std::cin.get();
}