Declaring struct in header file
Posted
by wrongusername
on Stack Overflow
See other posts from Stack Overflow
or by wrongusername
Published on 2010-04-28T20:39:11Z
Indexed on
2010/04/28
20:47 UTC
Read the original article
Hit count: 544
I've been trying to include a structure called "student" in a student.h
file, but I'm not quite sure how to do it.
My student.h
file code consists of entirely:
#include<string>
using namespace std;
struct Student;
while the student.cpp
file consists of entirely:
#include<string>
using namespace std;
struct Student {
string lastName, firstName;
//long list of other strings... just strings though
};
Unfortunately, files that use #include "student.h"
come up with numerous errors like error C2027: use of undefined type 'Student'
, error C2079: 'newStudent' uses undefined struct 'Student'
(where newStudent is a function with a Student
parameter), and error C2228: left of '.lastName' must have class/struct/union
. It appears the compiler (VC++) does not recognize struct Student from "student.h" or something?
I have tried declaring the whole struct in "student.h", but it didn't help either. How can I declare struct Student in "student.h" so that I can just #include "student.h" and start using the struct? BTW, it seems there are no compiler errors in student.h...
© Stack Overflow or respective owner