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

我一直在尝试在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?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值