问题描述:

I am following an SDL tutorial and have run across a problem. When I compile my program, it gives the errors

/home/cevent.h 9 error: expected unqualified-id before '-' token

/home/cevent.cpp 5 error: expected unqualified-id before '-' token

My code is as follows:

The Header file

//cevent.h

#ifndef CEVENT_H

#define CEVENT_H

#include <SDL/SDL.h>

class CEvent {

public:

CEvent();

virtual -CEvent();

void onEvent(SDL_Event *event);

virtual void onExit();

//and various other virtual method declarations

};

#endif // CEVENT_H

And the source file

//cevent.cpp

#include "cevent.h"

CEvent::CEvent() {}

CEvent::-CEvent() {}

void CEvent::onEvent(SDL_Event *event) {

switch(event->type) {

//some code for handling events

}

}

//some temporarily empty method definitions

I have dug through multiple online solutions to similar problems, but i can neither find one that satisfies my problem nor work out the solution based on what i have read.

网友答案:

to C++ destructor starts with ~ not -. See link

update

virtual -CEvent();

to

virtual ~CEvent();
//      ^
网友答案:
virtual -CEvent();

Should be

virtual ~CEvent();
        ^^^ a tilde
相关阅读:
Top