not declared in scope, even though declared in .h

c++, header, scope, struct

Solution

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:

- don't re-define `MAX_CHARS` in the `cpp` file.

- use include guards for the header.

Problem

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.

Original source