I have been stuck on this, my teacher doesn't even know what's going on. If someone could please help me that would be greatly appreciated.
I have declared item in the header file in the Line struct. However when calling on it in the Line::display() method, i get an error stating that the variable was not declared in the scope. I have showed my teacher and my peers and no one seems to know of the solutions.
Here is my .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;
};
And here is my .cpp file.
// Line.cpp
#include "Line.h"
#include <iostream>
using namespace std;
#define MAX_CHARS 40
void Line::display() const {
cout << no << ' ' << item << endl;
}
Any help with this is awesome. Thanks in advance.
If this is your actual code, you're probably getting the header from somewhere else. Try:
#include "C:\\fullPathToHeader\\Line.h"
#include <iostream>
using namespace std;
void Line::display() const {
cout << no << ' ' << item << endl;
}
Also:
MAX_CHARS
in the cpp
file.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With