关于类的声明! 新手求助.
高手帮忙看下. 程序没有错误,我声明了Weapon类还是显示没有定义类...PS:把两个类位置换一下运行正常.
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
class Weapon;
class Actor
{
private:
string _name;
int _dj;
Weapon _wuqi;
public:
Actor()
{ }
Actor(string name,int dj)
:_name(name),_dj(dj)
{
}
void set(Weapon &n)
{ _wuqi=n;
}
void display()
{
cout<<_name<<setw(4)<<_dj<<"级"<<endl;
_wuqi.show();
}
};
class Weapon
{
private:
string _name;
int _power;
public:
Weapon()
{ }
Weapon(string name,int power)
:_name(name),_power(power)
{
}
void show()
{
cout<<"武器名:"<<_name<<endl;
cout<<"攻击力:"<<_power<<endl;
}
};
int main()
{
Actor js("lvyan",20);
Weapon wuqi("打狗棒",25);
js.set(wuqi);
js.display();
return 0;
}