error: expected class-name before '(' token

Jul 11, 2018 at 1:17pm
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:27pm
What are you trying to "destruct" with these?
1
2
virtual void ~Next();
virtual void ~CountValues();
Jul 11, 2018 at 1:28pm
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
And now i have an another error: declaration of '~Board' as member of 'BoardImpl'.
Jul 11, 2018 at 3:25pm
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 ~
Jul 11, 2018 at 8:26pm
Thank you
Topic archived. No new replies allowed.