我一直坚持这个,我的老师甚至不知道发生了什么.如果有人能帮助我,我将不胜感激.
我已在Line结构的头文件中声明了item.但是当在Line :: display()方法中调用它时,我得到一个错误,指出该变量未在范围中声明.我向老师和同学们展示过,似乎没有人知道这些解决方案.
这是我的.h:
//Line.h
#define MAX_CHARS 40
struct Line {
public:
bool set(int n, const char* str);
void display() const;
private:
char item[MAX_CHARS];
int no;
};
Run Code Online (Sandbox Code Playgroud)
这是我的.cpp文件.
// Line.cpp
#include "Line.h"
#include <iostream>
using namespace std;
#define MAX_CHARS 40
void Line::display() const {
cout << no << ' ' << item << endl;
}
Run Code Online (Sandbox Code Playgroud)
对此的任何帮助都很棒.提前致谢.