Backslash36
Backslash36

Reputation: 805

Inheritance : expected class-name before ‘{’ token

I'm trying to create an exception class in C++ and it doesn't work. I've reduced the code to a minimum and I still can't find the error. Here is my header file :

#ifndef LISTEXCEPTION_H
#define LISTEXCEPTION_H

// C++ standard libraries
#include <exception>

/* CLASS DEFINITION */
class ListException: public exception {
};

#endif //LISTEXCEPTION_H

and here is the error I get :

error: expected class-name before ‘{’ token

This is quite unexpected. How do I solve this?

Upvotes: 6

Views: 1996

Answers (3)

juanchopanza
juanchopanza

Reputation: 227370

exception lives in the std namespace:

class ListException: public std::exception { ... }

Upvotes: 3

Jerry Coffin
Jerry Coffin

Reputation: 490018

It's subtly telling you that exception isn't the name of a class (with a declaration that's in scope, anyway).

You probably intended std::exception instead.

Upvotes: 4

Luchian Grigore
Luchian Grigore

Reputation: 258548

Did you mean

class ListException: public std::exception
//                          ^^^

?

Upvotes: 10

Related Questions