[Solved] Syntax for virtual functions

While making a function virtual in c++ where do I have to write virtual keyword? In the function declaration, before the function name, and after any attribute specifiers, along with the other specifiers (including the type specifier for the function’s return type). The general syntax for a declaration is simple-declaration: decl-specifier-seq<opt> init-declarator-list<opt> ; attribute-specifier-seq decl-specifier-seq<opt> … Read more

[Solved] Polymorphism vs Inheritance. Diffrence?

Here’s a version of your first example, that actually uses polymorphism: #include <iostream> #include <string> class shape { public: void setValues(int height_, int width_) { height = height_; width = width_; } virtual int area() = 0; // This is needed for polymorphism to work virtual std::string name() = 0; protected: int height; int width; … Read more