Jul 11, 2018 at 1:17pm UTC
So, where I have to declare the virtual destructor, I have this error
error: expected class-name before '(' token . I don't understand what's happening.
#ifndef BOARD_H
#define BOARD_H
const int SIZE = 3;
struct Board
{
public:
virtual void Next()=0;
virtual int CountValues()=0;
};
#endif // BOARD_H
#ifndef BOARDIMPL_H
#define BOARDIMPL_H
#include "board.h"
class BoardImpl: public Board
{
void Print() const;
protected:
int _board[SIZE];
public:
BoardImpl();
void Next();
int CountValues();
// TODO: 04. to declare the virtual destructor
virtual void ~Next();
virtual void ~CountValues();
protected:
virtual void Init();
int RandomValue();
};
#endif // BOARDIMPL_H
Jul 11, 2018 at 1:28pm UTC
A class can only have one destructor. It must be named ~ followed by the name of the class, and it can't have a return type.
A virtual destructor for the Board class would look like virtual ~Board();
Jul 11, 2018 at 2:16pm UTC
And now i have an another error: declaration of '~Board' as member of 'BoardImpl'.
Jul 11, 2018 at 3:25pm UTC
Member function ~Board() goes in class Board
Member function ~BoardImpl() goes in class BoardImpl
The destructor has the same name as the class it is in and is prefixed by a ~