Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inheritance : expected class-name before ‘{’ token

Tags:

c++

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?

like image 974
Backslash36 Avatar asked Jan 24 '13 15:01

Backslash36


3 Answers

Did you mean

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

?

like image 94
Luchian Grigore Avatar answered Sep 21 '22 12:09

Luchian Grigore


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.

like image 31
Jerry Coffin Avatar answered Sep 21 '22 12:09

Jerry Coffin


exception lives in the std namespace:

class ListException: public std::exception { ... }
like image 30
juanchopanza Avatar answered Sep 22 '22 12:09

juanchopanza