c++ - not declared in scope, even though declared in .h -


i have been stuck on this, teacher doesn't know what's going on. if please me appreciated.

i have declared item in header file in line struct. when calling on in line::display() method, error stating variable not declared in scope. have showed teacher , peers , no 1 seems know of solutions.

here .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 .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 awesome. in advance.

if actual code, you're getting header 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 cpp file.
  • use include guards header.

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -