why am I getting discard qualifiers error:
customExc.cpp: In member function 'virtual const char* CustomException::what() const': customExc.cpp: error: passing 'const CustomException' as 'this' argument of 'char customException::code()' discards qualifiers
in the following code example
#include <iostream> class CustomException: public std::exception { public: virtual const char* what() const throw() { static std::string msg; msg = "Error: "; msg += code(); // <---------- this is the line with the compile error return msg.c_str(); } char code() { return 'F'; } };
I searched around SOF before considering simulation issues.
I have already added const to all possible places.
Please enlighten me - I do not understand ...
EDIT : here are the steps to play on Ubuntu-Carmic-32bit (g ++ v4.4.1)
- save example as
customExc.cpp - type
make customExc.o
EDIT : The error is related to CustomException . The Foo class has nothing to do with it. So I deleted it.
c ++ const g ++
anon
source share