qq_33031101 2016-04-24 11:55 采纳率: 0%
浏览 2991

新手求助,C++的头文件引用问题

为什么#include "container.h"报错说打不开source file啊,我完全不知道怎么回事,啊啊啊啊啊,求帮助

#ifndef _CONTAINER

#define _CONTAINER
#include
using namespace std;
class container
{
protected:
int numOfHeal;
int numOfMW;
public:
container();
void set(int heal_n, int mw_n);
int nOfHeal();
int nOfMW();
void display();
bool useHeal();
bool useMW();
};
container::container()
{
set(0, 0);
};

void container::set(int heal_n, int mw_n)
{
    numOfHeal = heal_n;
    numOfMW = mw_n;
};


int container::nOfHeal()
{
    return numOfHeal;
};


int container::nOfMW()
{
    return numOfMW;
};


void container::display()
{
    cout << "Your bag contains: " << endl;
    cout << "Heal(HP+100): " << numOfHeal << endl;
    cout << "Magic Water (MP+80): " << numOfMW << endl;
};


bool container::useHeal()
{
    numOfHeal--;
        return 1;       
};

//use magic water
bool container::useMW()
{
    numOfMW--;
    return 1;
};

#endif

#ifndef _PLAYER
#define _PLAYER

#include

#include

#include "container.h"
#include
using namespace std;
enum job { sw, ar, mg };

class player
{
friend void showinfo(player &p1, player &p2);
friend class swordsman;

protected:
int HP, HPmax, MP, MPmax, AP, DP, speed, EXP, LV;

string name;    
job role;       
container bag;  

public:
virtual bool attack(player &p) = 0;
virtual bool specialatt(player &p) = 0;
virtual void isLevelUp() = 0;

void reFill();      
bool death();       
void isDead();      
bool useHeal();     
bool useMW();       
void transfer(player &p);   
void showRole();    

private:
bool playerdeath;

};
void player::reFill()
{
HP = HPmax;

MP = MPmax;
}

bool player::death()
{
return playerdeath;
};

void player::isDead()
{
if (HP <= 0)

cout << name << " is Dead." << endl;
system("pause");
playerdeath = 1;

}
};

bool player::useHeal()
{
if (bag.nOfHeal()>0)
{
HP = HP + 100;
if (HP>HPmax)

HP = HPmax;

cout << name << " used Heal, HP increased by 100." << endl;
bag.useHeal();

system("pause");
return 1;

}
else

{
cout << "Sorry, you don't have heal to use." << endl;
system("pause");
return 0;

}
};

bool player::useMW()
{
if (bag.nOfMW()>0)
{
MP = MP + 100;
if (MP>MPmax)
MP = MPmax;
cout << name << " used Magic Water, MP increased by 100." << endl;
bag.useMW();
system("pause");
return 1;

}
else
{
cout << "Sorry, you don't have magic water to use." << endl;
system("pause");
return 0;
}
}

// possess opponent's items after victory
void player::transfer(player &p)
{
cout << name << " got" << p.bag.nOfHeal() << " Heal, and " << p.bag.nOfMW() << " Magic Water." << endl;
system("pause");
p.bag.set(p.bag.nOfHeal(), p.bag.nOfMW());
};
void player::showRole()
{
switch (role)
{
case sw:
cout << "Swordsman";
break;
case ar:
cout << "Archer";
break;
case mg:
cout << "Mage";
break;
default:
break;
}
};

// display character's job
void showRole()
{
system("cls");
cout << "##############################################################" << endl;
cout << "# Player" << setw(10) << p1.name << " LV. " << setw(3) << p1.LV
<< " # Opponent" << setw(10) << p2.name << " LV. " << setw(3) << p2.LV << " #" << endl;
cout << "# HP " << setw(3) << (p1.HP <= 999 ? p1.HP : 999) << '/' << setw(3) << (p1.HPmax <= 999 ? p1.HPmax : 999)
<< " | MP " << setw(3) << (p1.MP <= 999 ? p1.MP : 999) << '/' << setw(3) << (p1.MPmax <= 999 ? p1.MPmax : 999)
<< " # HP " << setw(3) << (p2.HP <= 999 ? p2.HP : 999) << '/' << setw(3) << (p2.HPmax <= 999 ? p2.HPmax : 999)
<< " | MP " << setw(3) << (p2.MP <= 999 ? p2.MP : 999) << '/' << setw(3) << (p2.MPmax <= 999 ? p2.MPmax : 999) << " #" << endl;
cout << "# AP " << setw(3) << (p1.AP <= 999 ? p1.AP : 999)
<< " | DP " << setw(3) << (p1.DP <= 999 ? p1.DP : 999)
<< " | speed " << setw(3) << (p1.speed <= 999 ? p1.speed : 999)
<< " # AP " << setw(3) << (p2.AP <= 999 ? p2.AP : 999)
<< " | DP " << setw(3) << (p2.DP <= 999 ? p2.DP : 999)
<< " | speed " << setw(3) << (p2.speed <= 999 ? p2.speed : 999) << " #" << endl;
cout << "# EXP" << setw(7) << p1.EXP << " Job: " << setw(7);
p1.showRole();
cout << " # EXP" << setw(7) << p2.EXP << " Job: " << setw(7);
p2.showRole();
cout << " #" << endl;
cout << "--------------------------------------------------------------" << endl;
p1.bag.display();
cout << "##############################################################" << endl;
};

#endif

  • 写回答

4条回答

  • oyljerry 2016-04-24 13:08
    关注

    这个头文件路径是否正确 你编译器能否直接打开

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序