fatal error LNK1120: 1 unresolved externals出现这个东西了
#include"iostream"usingnamespacestd;classAnimal{public:Animal();~Animal();intSetAge()...
#include"iostream"
using namespace std;
class Animal
{
public:
Animal();
~Animal();
int SetAge()const{
return itsAge;
}
void SetAge(int age){
itsAge=age;
}
protected:
int itsAge;
};
class dog:public Animal{
public:
dog();
~dog();
};
Animal::Animal():
itsAge(5){}
Animal::~Animal(){}
dog::dog(){}
int main(){
dog jack;
cout<<"狗的年龄是:"<<jack.SetAge()<<"岁\n";
return 0;
} 展开
using namespace std;
class Animal
{
public:
Animal();
~Animal();
int SetAge()const{
return itsAge;
}
void SetAge(int age){
itsAge=age;
}
protected:
int itsAge;
};
class dog:public Animal{
public:
dog();
~dog();
};
Animal::Animal():
itsAge(5){}
Animal::~Animal(){}
dog::dog(){}
int main(){
dog jack;
cout<<"狗的年龄是:"<<jack.SetAge()<<"岁\n";
return 0;
} 展开
1个回答
展开全部
“未决议的外部符号”,因为dog的析构函数只有声明,没有定义;添加上dog::~dog()的定义即可;另外,第一次SetAge命名为GetAge更合理:
#include"iostream"
using namespace std;
class Animal
{
public:
Animal();
~Animal();
int SetAge() const { // 命名为 GetAge 更合理
return itsAge;
}
void SetAge(int age){
itsAge=age;
}
protected:
int itsAge;
};
class dog:public Animal{
public:
dog();
~dog();
};
Animal::Animal() : itsAge(5){}
Animal::~Animal(){}
dog::dog(){}
// dog 类的 析构函数
dog::~dog(){}
int main(){
dog jack;
cout<<"狗的年龄是:"<<jack.SetAge()<<"岁\n";
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询