gpt4 book ai didi

c++ - 创建构造函数时未解析的外部符号

转载 作者:行者123 更新时间:2023-11-30 01:34:08 25 4
gpt4 key购买 nike

<分区>

删除构造函数行后错误消失。

Dog::Dog(std::string name, double height, double weight, std::string sound) : Animal(name, height, weight) {
this -> sound = sound;
}


void Dog::ToString() {
//std::cout << this->name << " is " << this->height << " cm's tall and " << this->weight << " kg's in weight" << std::endl;
//cannot do the line above as it is private, if it were to be protected we could call it. "sharing with childs of class"

std::cout << GetName() << " is " << GetHeight() << " cm's tall and " << GetWeight() << " kg's in weight" << std::endl;
}

enter image description here

class Animal {
private:
std::string name;
double height;
double weight;


static int numOfAnimals;
static bool canTalk;

public:
std::string GetName() {
return name;
}

double GetHeight() {
return height;
}

double GetWeight() {
return weight;
}

void SetName(std::string name) {
this->name = name;
}

void SetHeight(double height) {
this->height = height; //height that is passed in through parameter becomes the height
}
void SetWeight(double weight) {
this->weight = weight;
}

void SetAll(std::string, double, double);

Animal(std::string, double, double); //constructor
Animal(); //for when no parameters are passed
~Animal(); //destructor

static int GetNumOfAnimals() {
return numOfAnimals;
}
void ToString();
};

@inisheer 要求的动物类的代码和构造函数

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com