If I have have a classes "Card" (Base Class) "CardOfType1" (Derived Class) and a class named "Player" having pointers of type 'Card' referring to 'CardOfType1'. Is it possible that we have a pure virtual function named 'playCard(Player enemyPlayer)'?
For more understanding, the code is given below
class Card
{
public:
virtual void playCard(Player enemyPlayer) = 0;
};
class CardOfType1
{
public:
void playCard(Player enemyPlayer)
{
//Some Code Goes here
}
};
class Player
{
stack<Card *> deckOfCards
//.
//.
//.
};
yes, a PVF
can have parameters.
virtual void playCard(Player enemyPlayer) = 0;
here = 0
(is not assigning), Simply we are informing to compiler that function will be pure
and does not having any body(where its declared, in that class), but it can have parameter.
From the n4659 C++
standard
A pure virtual function need be defined only if called with, or as if with (15.4), the qualified-id syntax (8.1).
class shape {
point center;
public:
virtual void rotate(int) = 0; // pure virtual
virtual void draw() = 0; // pure virtual
};
But there is another observation
A function declaration cannot provide both a pure-specifier and a definition — end note ]
struct C {
virtual void f() = 0 { };
};