【发布时间】:2014-04-22 22:11:41
【问题描述】:
我不确定是什么问题。它给了我错误:
error C2679: binary '
我重载了
#ifndef ANIMAL_H_
#define ANIMAL_H_
#include <iostream>
#include <string>
using namespace std;
static int counter;
static int getAnimalCount() { return counter; }
class Animal {
protected:
string *animalType;
public:
virtual void talk() = 0;
virtual void move() = 0;
string getAnimalType() { return *animalType; }
//PROBLEM RIGHT HERE V
friend ostream& operator<<(ostream&out, Animal& animal) {
return out << animal.getAnimalType() << animal.talk() << ", " << animal.move();
};
~Animal() {
counter--;
animalType = NULL;
}
};
class Reptile : public Animal {
public:
Reptile() { animalType = new string("reptile"); };
};
class Bird : public Animal {
public:
Bird() { animalType = new string("bird"); };
};
class Mammal : public Animal{
public:
Mammal() { animalType = new string("mammal"); };
};
#endif /* ANIMAL_H_ */
【问题讨论】:
标签: c++ overloading