So I have an abstract class Product with fields name and price. There are a few classes that inherit from Product, and the reason Product is abstract is because these subclasses have to implement this function (defined in Product):
virtual std::string getCategory()=0;
Category is not a field, it just depends on which subclass we have and in some cases on the price.
Now I want an output operator for the subclasses of Product, but since I only want to print the name and price, I did this in Product.h:
friend std::ostream& operator<<(std::ostream& os, const Product& secondOperand);
And this in Product.cpp:
ostream& operator<<(ostream& outputStream, Product& secondOperand){
outputStream << "["<<secondOperand.getName()<<" "<<secondOperand.getPrice()<<"]"<<endl;
return outputStream;
}
Now I get this error in visual studio:
Error C2259: 'Product' : cannot instantiate abstract class
I don't want to implement this output for every subclass (cause then I have to literally copy everything which isn't ideal). Also, I started out with Product being not pure virtual, but then I had Linker errors for the getCategory() functions...