头文件问题
先上逻辑有点混乱的代码(程序简单没加注释)///////////////////main.cpp
#include"man.h"
#include<iostream>
using namespace std;
char ManOrWoman;
void Man();
void Woman();
int main()
{
cout<<"***********WELCOME***********"<<endl;
cout<<"Are you a man or a woman?(M/W)"<<endl;
cin>>ManOrWoman;
if(ManOrWoman=='m'||ManOrWoman=='M')
Man();
else
Woman();
return 0;
}
void Woman()
{
int l, g, ag, wei, hi;
string jo, nam;
int car, hou;
unsigned mo, sala;
cout<<"Your name:";cin>>nam;cout<<"Your age:";cin>>ag;cout<<"Your weight:";cin>>wei;cout<<"Your job:";cin>>jo;
cout<<"Leghth of you vagina:";cin>>l;cout<<"Value of your glam:";cin>>g;
cout<<"Your height::";cin>>hi;cout<<"Number of you cars:";cin>>car;
cout<<"Number of you houses:";
cin>>hou;cout<<"How much is your money:";cin>>mo;cout<<"How much is your salary:";cin>>sala;
human *you(ag,wei,hi,jo,nam,car,hou,mo,sala);
you=new woman(l,g);
man SB(180,10,25,57,160,"SB","2B",0,0,10000000,0);
man ZHY(175,0,23,55,180,"2b","周鸿祎",5,5,1000000,50000);
man MHT(20,-8,2,180,55,"SB","马化腾",50,50,1000000000,0);
man WLGQ(189,60,29,55,189,"技术宅","[我嘞个去,名字被屏蔽了]",2,2,10000,1000);
man NB(190,87,39,67,189,"工人最伟大","盖茨(艺名)",0,1,100000,5000);
bool sb=SB.ShowL(you); bool mht=MHT.ShowL(you);
bool zhy=ZHY.ShowL(you); bool wlgq=WLGQ.ShowL(you); bool nb=NB.ShowL(you);
if(sb)
cout<<"Congratulations!"<<endl;
else
{
if(zhy)
cout<<"Congratulations!"<<endl;
else{
if(mht)
cout<<"Congratulations!"<<endl;
else
{
if(wlgq)
cout<<"Congratulations!"<<endl;
else
{
if(nb)
cout<<"Congratulations!"<<endl;
else
cout<<"没人要的屌丝,滚!"<<endl;
}
}
}
}
}
void Man()
{
int l, g, ag, wei, hi;
string jo, nam;
int car, hou;
unsigned mo, sala;
cout<<"Your name:";cin>>nam;cout<<"Your age:";cin>>ag;cout<<"Your weight:";cin>>wei;cout<<"Your job:";cin>>jo;
cout<<"Leghth of you penis:";cin>>l;cout<<"Value of your glam:";cin>>g;
cout<<"Your height::";cin>>hi;cout<<"Number of you cars:";cin>>car;
cout<<"Number of you houses:";
cin>>hou;cout<<"How much is your money:";cin>>mo;cout<<"How much is your salary:";cin>>sala;
human *you(ag,wei,hi,jo,nam,car,hou,mo,sala);
you=new man(l,g);
woman SB(180,10,25,57,160,"SB","2B",0,0,10000000,0);
woman ZHY(175,0,23,55,180,"2b","周鸿祎",5,5,1000000,50000);
woman MHT(20,-8,2,180,55,"SB","马化腾",50,50,1000000000,0);
woman WLGQ(189,60,29,55,189,"技术宅","[我嘞个去,名字被屏蔽了]",2,2,10000,1000);
woman NB(190,87,39,67,189,"工人最伟大","盖茨(艺名)",0,1,100000,5000);
bool sb=SB.ShowL(you); bool mht=MHT.ShowL(you);
bool zhy=ZHY.ShowL(you); bool wlgq=WLGQ.ShowL(you); bool nb=NB.ShowL(you);
if(sb)
cout<<"Congratulations!"<<endl;
else
{
if(zhy)
cout<<"Congratulations!"<<endl;
else{
if(mht)
cout<<"Congratulations!"<<endl;
else
{
if(wlgq)
cout<<"Congratulations!"<<endl;
else
{
if(nb)
cout<<"Congratulations!"<<endl;
else
cout<<"没人要的屌丝,滚!"<<endl;
}
}
}
}
}
/////////////////////////man.h
#include"woman.h"
#include<iostream>
using namespace std;
#ifdef MAN_H
#define MAN_H
class man
{
public:
man(int l,ine g,int ag,int wei,int hi,string jo,string nam,int car,int hou,unsigned mo,unsigned sala);
bool ShowL(man me,woman lo);
void AI(man me,woman lo);
bool Interest(woman lo);
private:
int Leghth,glam;
bool doEsSheLove;
char yEs;
string sty;
int age,weight,height;
string Name,sex,job;
int cars,houses;
unsigned money,salary;
};
man::man(int l,int g,int ag,int wei,int hi,string jo,string nam,int car,int hou,unsigned mo,unsigned sala)
{
Leghth=l;glam=g;age=ag; weight=wei;
height=hi;
Name=nam;
cars=car;
houses=hou;
money=mo;
job=jo;
if(glam>=50 && money>=10000000)
sty="Gaofushuai";
else
sty="Diaosi";
}
bool man::ShowL(man me,woman lo)
{
cout<<"Darling, come on!T`m "<<me.Name<<"and I`m a "<<sty
<<endl<<"Value of my glamour:"<<me.glam<<", my height:"<<me.height<<", leighth of my penis"<<me.Leghth<<"mm."<<endl;
cout<<"I have "<<me.Cars<<"cars and "<<me.Houses<<", and 128√e980!"<<endl;
cout<<"I cannot wait!!!"<<endl;
lo.Interest(me);
if(lo.yEs=='Y'||lo.yEs=='y')
return true;
else
return false;
}
bool man::Interest(woman lo)
{
cout<<"Are you interted in her?(Y/N)"<<endl;
cin>>lo.yEs;
if(lo.yEs=='Y'||lo.yEs=='y')
return true;
else
return false;
}
#endif
////////////////////////////woman.h
#include"man.h"
#include<iostream>
using namespace std;
#ifdef WOMAN_H
#define WOMAN_H
class woman
{
public:
woman(int l,ine g,int ag,int wei,int hi,string jo,string nam,int car,int hou,unsigned mo,unsigned sala);
bool ShowL(woman me,man lo);
bool Interest(woman me,man lo);
private:
int Leghth,glam;
bool doEsHeLove;
char yEs;
string sty;
int age,weight,height;
string Name,sex,job;
int cars,houses;
unsigned money,salary;
};
woman::woman(int l,int g,int ag,int wei,int hi,string jo,string nam,int car,int hou,unsigned mo,unsigned sala)
{
Leghth=l;glam=g;age=ag; weight=wei;
height=hi;
Name=nam;
sex=se;
cars=car;
houses=hou;
money=mo;
if(glam>=50 && money>=10000000)
sty=Baifumei;
else
sty=Diaosi;
}
bool woman::ShowL(woman me,man lo)
{
cout<<"Darling, come on!I`m "<<me.Name<<"and I`m a "<<sty
<<endl<<"Value of my glamour:"<<me.glam<<", my height:"<<me.height<<", leighth of my vagina"<<me.Leghth<<endl;
cout<<"I have "<<me.Cars<<"cars and "<<me.Houses<<", and 128√e980!"<<endl;
cout<<"I cannot wait!!!"<<endl;
lo.Interest(me);
if(lo.yEs=='Y'||lo.yEs=='y')
return true;
else
return false;
}
bool woman::Interest(man lo)
{
cout<<"Are you interted in him?(Y/N)"<<endl;
cin>>lo.yEs;
if(lo.yEs=='Y'||lo.yEs=='y')
return true;
else
return false;
}
#endif
有两个问题:
一、编译时提示无限递归(貌似是这问题,机器翻译的,我不知道确切的翻译)
e:man.h(1) : warning C4182: #include nesting level is 363 deep; possible infinite recursion
e:man.h(1) : fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit
二、《c++ primer 4》上把头文件保护符说的神乎其神的,但是头文件保护符是不是真的那么重要?上边的程序不加保护符会提示一大堆奇怪的错误,加上保护符就会提示无限递归
[ 本帖最后由 sfwyx 于 2012-6-30 18:05 编辑 ]