I think it explains pretty clearly step by step how. At what part of it you got stuck?
You need to give some implementation to play in Game class or do virtual void play() = 0; which makes it "pure virtual", otherwise compiler going to complain about that. Also you need to ideally add public: to the derived classes also. Otherwise it looks correct. If you want to make it a bit more advanced, you can dynamically allocate the games in main function and delete them at the end or use std::unique_ptr<Game>
Okk sir, compiler didn't complain in my case tho And one more ques why should ideally public be added to derived class? Compiler is not complaining abt it
I think if you don't make it public and try to call play on the derived class (which you don't do in your program but may want to do in reality in some cases) then that won't compile. But I may be wrong
Yes, when I create a pointer to derived class and try to access play() its showing declared private. Thankyou sir!!
I usually use struct to denote that it's not an OOP S.O.L.I.D. class but just a bunch of data tied together
but it is de facto
well, it can be or not, depending on how you use it
add = 0 after void play() in Games class
Обсуждают сегодня