Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Class 'undeclared identifier"
    primarykey
    data
    text
    <p>This is really frustrating, I've tried multiple variations of my class and constructor, sifted through pages of google results and other questions on this site but I can't figure it out. I believe the error is something simple that I'm overlooking.</p> <p>Error code:</p> <pre><code>1&gt;main.cpp(60): error C2065: 'Student' : undeclared identifier 1&gt;main.cpp(60): error C2146: syntax error : missing ';' before identifier 'newStudent' 1&gt;main.cpp(60): error C3861: 'newStudent': identifier not found </code></pre> <p>student.h</p> <pre><code>#ifndef STUDENT_H #define STUDENT_H class Student { private: static const int SIZE = 7; // initial size of the array int *Students; // Students will point to the dynamically allocated array //int numStudents; // number of students currently in the list int rosterSize; // the current size of the roster int student_id; string name; string classification; public: Student(); // constructor; initialize the list to be empty ~Student(); void set_id(int); void set_name(string); void set_class(string); int print_id(); string print_name(); string print_class(); //void enrollStudent(); //void Print(ostream &amp;output) const; // print the list to output }; #endif </code></pre> <p>student.cpp</p> <pre><code> #include &lt;iostream&gt; #include &lt;string&gt; #include "student.h" #define PROMPT "class&gt; " using namespace std; Student::Student(){ // declared here right? student_id = 0; name = ""; classification = ""; } Student::~Student(){ //delete Student } void Student::set_id( int i ){ student_id = i; } void Student::set_name( string n ){ name = n; } void Student::set_class( string c ){ classification = c; } int Student::print_id(){ return student_id; } string Student::print_name(){ return name; } string Student::print_class(){ return classification; } </code></pre> <p>main.cpp</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include "student.h" #define PROMPT "class&gt; " using namespace std; //**** Implement Error Handling ****\\ enum errorType { UNKNOWN_ERROR, INPUT_ERROR, HANDLER, NUM_ERRORS }; // error messages string errorMessage[NUM_ERRORS]= { "Unknown Error\n", "Input Error\n", }; // error handler void handleError(errorType err) { if(err &gt; 0 &amp;&amp; err &lt; NUM_ERRORS) cout&lt;&lt; "Error: "&lt;&lt; errorMessage[err]; else cout&lt;&lt; "Error: "&lt;&lt; errorMessage[UNKNOWN_ERROR]; } //**** END Error Handling ****\\ void getInput() { int id; string n, c; cin&gt;&gt;id&gt;&gt;n&gt;&gt;c; //cout&lt;&lt;id&lt;&lt;"-"&lt;&lt;n&lt;&lt;"-"&lt;&lt;c&lt;&lt;endl; Student newStudent(); //****WORK DAMN U! //set_id(id); //print_id(); return; } int main() { //Student newStudent(); /* &lt;-- why doesn't this work?!*/ string input = ""; bool finished = false; cout&lt;&lt;PROMPT; // prompt the user while(!finished) { if(input!="") cout&lt;&lt;PROMPT; cin&gt;&gt;input; if(input=="enroll") { cout&lt;&lt;PROMPT&lt;&lt;"Enroll student:"&lt;&lt;endl; getInput(); } else if(input=="drop") { cout&lt;&lt;PROMPT&lt;&lt;"Enter ID:"&lt;&lt;endl; } else if(input=="roster") { cout&lt;&lt;"This will print formatted list of students"&lt;&lt;endl; } else if(input=="quit") { finished=true; } else handleError(errorType(1)); } } </code></pre> <p>Just as a note, my professor said adding #include student.h<br> to my main.cpp would fix my issue. OBVIOUSLY NOT because I included it in my student.cpp SO THANKS. ಠ_ಠ</p> <p>tl;dr here is a smaller barebones version that gets same errors:</p> <pre><code>#include&lt;iostream&gt; #include&lt;string&gt; #define PROMPT "class&gt; " using namespace std; class Student { private: int student_id; string name; string classification; public: Student(); // constructor ~Student(); void set_id(int); int print_id(); }; Student::Student(){ student_id = 0; name = ""; classification = ""; } Student::~Student(){ //delete Student } void Student::set_id( int i ){ student_id = i; } int Student::print_id(){ return student_id; } void messenger(){ int id; Student newStudent(); cin&gt;&gt;id; //this will drop the name and class newStudent.set_id(id); newStudent.print_id(); return; } void main() { //Student newStudent(); string input=""; bool finished=false; cout&lt;&lt;PROMPT; // prompt the user while(!finished) { if(input!="") cout&lt;&lt;PROMPT; cin&gt;&gt;input; if(input=="enroll") { cout&lt;&lt;PROMPT&lt;&lt;"Enroll student:"&lt;&lt;endl; messenger(); //cin&gt;&gt;input; //newStudent.enroll(input ); } else if(input=="drop") { cout&lt;&lt;PROMPT&lt;&lt;"Enter ID:"&lt;&lt;endl; } else if(input=="roster") { cout&lt;&lt;"This will print formatted list of students"&lt;&lt;endl; } else if(input=="quit") { finished=true; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload