Inheritance: expected class name before '{token

I am trying to create an exception class in C ++ and it does not work. I have reduced the code to a minimum, and I still cannot 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 pretty unexpected. How to solve this?

+5
source share
3 answers

You meant

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

?

+8
source

This subtly tells you that exception- this is not a class name (with a declaration that is in scope, anyway).

You probably used std::exception.

+4
source

exceptionlives in a namespace std:

class ListException: public std::exception { ... }
+3
source

All Articles