[C.C++] c语言 结构体头文件,C,如何在头文件中声明一个结构体

35 0
Honkers 昨天 17:18 | 显示全部楼层 |阅读模式

我一直在尝试在student.h文件中包含一个名为“student”的结构,但我不太清楚如何做.

我的student.h文件代码完全包括:

#include

using namespace std;

struct Student;

而student.cpp文件完全包含:

#include

using namespace std;

struct Student {

string lastName, firstName;

//long list of other strings... just strings though

};

不幸的是,使用#include“student.h”的文件会出现诸如此类的错误

error C2027: use of undefined type 'Student'

error C2079: 'newStudent' uses undefined struct 'Student' (where newStudent is a function with a `Student` parameter)

error C2228: left of '.lastName' must have class/struct/union

看来编译器(VC)不能从“student.h”中识别struct Student?

如何在“student.h”中声明struct Student,以便我可以#include“student.h”并开始使用struct?

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行