I am trying to print the enum class(will use some kind of map to print car, house).
In below code where should I stick the function to operator overload << ?
PS: this is a contrived example.
#include <iostream>
#include <vector>
#include <memory>
enum class property_type {CAR, HOUSE};
class Property
{
public:
virtual property_type type() = 0;
};
class Car : public Property
{
public:
Car(std::string name) : mName(name) {}
std::string mName;
property_type type() {return property_type::CAR;}
};
class House : public Property
{
public:
House(std::string name) : mName(name) {}
std::string mName;
property_type type() {return property_type::HOUSE;}
};
class Person
{
public:
std::vector< std::shared_ptr<Property> > properties;
};
int main()
{
Person x;
auto y = std::shared_ptr<Property>(new Car("my car"));
auto z = std::shared_ptr<Property>(new House("my house"));
x.properties.push_back(y);
x.properties.push_back(z);
for (auto i : x.properties) {
std::cout << i->type() << std::endl;
}
return 0;
}