当我将函数 print 与其他所有内容一起放入 pointerStruct.cpp 时,它工作正常,但是当我尝试将函数分离到头文件中时,我不再能够找出问题所在。任何想法都会很棒。
指针结构.cpp
#include<iostream>
#include<string.h>
#include "pointerStru.h"
using namespace std;
struct student
{
char name[20];
int num;
float score[3];
};
int main()
{
struct student stu;
PointerStru pstttt;
stu.num=12345;
strcpy(stu.name,"li li");
stu.score[0]=67.5;
stu.score[1]=89;
stu.score[2]=78.6;
pstttt.print(&stu);
}
//pointerStru.h
#ifndef PointerStru_H_INCLUDED
#define PointerStru_H_INCLUDED
#include <iostream>
using namespace std;
class PointerStru{
private:
public:
void print(struct student *p)
{
cout << "*p " << p << endl;
cout<<p->num<<"\n"<<p->name<<"\n"<<p->score[0]<<"\n"
<<p->score[1]<<"\n"<<p->score[2]<<"\n";
cout<<" ";
}
};
#endif // PointerStru_H_INCLUDED