10/04/25 23:07:04
>>500
解決できそう?
#include <iostream>
#include <vector>
class Animal {
public: virtual void bark() { };
};
class Dog : public virtual Animal {
public: virtual void bark() { std::cout << "bow wow" << std::endl; }
};
class Cat : public virtual Dog {
public: virtual void bark() { std::cout << "meaow" << std::endl; }
};
int main() {
std::vector<Animal*> animal;
animal.push_back(new Dog());
animal.push_back(new Cat());
animal[0]->bark(); // Dog
animal[1]->bark(); // Cat
}