注册 登录
编程论坛 C++教室

C++关于3个文件的定义头文件、定义函数原型、定义main(),然后多文件编译连接问题

沿途有鬼 发布于 2008-08-02 13:26, 1662 次点击
VC6.0中如何多文件编译连接啊~(我是新手实在不会)
VC6.0中如何多文件编译连接啊~(跪求答案)
//golf.h 包含空间名定义的头文件
#ifndef GOLF_H_
#define GOLF_H_


namespace go
{
const int Len=40;
struct golf
{
char fullname[Len];
int handicap;
};

void setgolf(golf & g,const char * name,int hc);

int setgolf(golf & g);

void handicap(golf & g,int hc);

void showgolf(const golf & g);

}

#endif


//golf.cpp对应上面头文件的函数定义
#include<iostream>
#include"golf.h"

namespace go
{
using std::cosh;
using std::cin;
using std::endl;
void setgolf(golf & g,const char * name,int hc)
{

strcpy(g.fullname,name);

g.handicap=hc;
}

int setgolf(golf & g)
{
cout<<"Enter a name: ";
cin.getline(g.fullname,40);
cin.getline(g.fullname,40);
cin.ignore(1024,'\n');
cout<<"Enter a scores: ";
cin>>g.handicap<<endl;
}

void handicap(golf & g,int hc)
{
g.handicap=hc;
}

void showgolf(const golf & g)
{
cout<<g.fullname<<endl<<g.handicap<<endl;
}



//91main.cpp main()功能函数定义

#include<iostream>
#include"golf.h"

int main()
{
using go::golf;
using go::setgolf;
using go::handicap;
using go::showgolf;
golf jjyy;
golf xiha;
golf hd;

char * ch="my name is wen sheng ';
int t=90,n=66;
setgolf(jjyy,ch,t);
showgolf(jjyy);
while(cin)
{
setgolf(xiha);
showgolf(xiha);
}
handicap(hd,n);
showgolf(hd);
return 0;
}


我是新手从来没弄过多文件编译连接,我的思路就是首先定义个头文件以空间名称的形式包含所有变量和函数原型定义。接着用glof.cpp对应头文件中的函数原型的定义,最后用91main.cpp调用这些函数实现功能。

我不知VC6.0如何操作编译多文件,请大家告诉我别且试试我的源程序是否能通过,我自己按自己的方法试验了下说是找不到头文件,摆脱大家了~



91pe.cpp是我定义的头文件
golf.cpp是函数定义
91main是调用函数的定义

只有本站会员才能查看附件,请 登录


我编译连接运行后出现找不到”golf.h"头文件错误,请大家帮我测试下错在哪里,我把91pe.cpp改成了91pe.h后还是不行~请大家帮帮忙啊~!

[[it] 本帖最后由 沿途有鬼 于 2008-8-2 20:34 编辑 [/it]]
2 回复
#2
忘记喧嚣2008-08-02 15:07
你写的是什么啊 ....namespace go.... 没见过 大概是我孤陋寡闻文吧
而且你既然要找 golf.h  那你为什么文件名要叫 91pe.cpp 或者91pe.h

你文件都没得叫 golf.h 的文件 肯定找不到三...
#3
相信1232015-06-20 10:29
为什么要用namespace go将那些内容裹起来啊,好像没必要吧,后面也觉得好复杂的样子,我是菜鸟,求解
1