So, I have 2 classes, one inherited by other and enum class,which does not play a role in my question, but I will quote it anyway:
enum class PetType {
Cat,
Dog,
Q
};
class Pet {
protected:
std::string name;
size_t age;
std::string breed;
static PetType spice;
public:
...
friend std::ostream& operator<< (std::ostream& out, const Pet& pet);
friend std::ostream& operator<< (std::ostream& out, const PetType& pet);
};
class Dog : public Pet {
private:
static PetType spice;
public:
...
};
PetType Dog::spice = PetType::Dog;
PetType Pet::spice = PetType::Q;
The main problem is here: i have an 2 operator's <<. First one is just help for me to cout<<PetType. Second one looks like these:
std::ostream& operator<< (std::ostream& out, const Pet& pet) {
out << "My name is " << pet.name << std::endl;
out << "I am " << pet.spice << ", " << pet.breed << std::endl;
out << "I am " << pet.age << " years old" << std::endl;
return out;
}
And, I have a vector with different Pet's. In the function of outputting this vector to the console, I cycle through it with cycle for and do smth like this:
std::cout << pets[i];
I want it to output my petType, of course. But it's outputting Q as my petType, which i choose a basic one for abstract class Pet. How can i fix this, please help!!!