error: virtual outside class declaration
Bonjour,
Je viens de commencer le CPP et c'est pas evident de faire javaToCpp mdrr donc voila j'essaye de faire mes propres exceptions et voici ce que le compilo me dit :
Code:
1 2 3 4 5 6 7
|
g++ -Wall -W -Wextra -Werror -pedantic -O -DNDEBUG -I./include -c exception.cc -o exception.o
exceptioncc:19: error: virtual outside class declaration
exception.cc:24: error: virtual outside class declaration
exception.cc:24: error: prototype for `const char* MyException::what()' does not match any in class `MyException'
exception.hh:15: error: candidate is: virtual const char* MyException::what() const
gmake: *** [exception.o] Error 1 |
et voici le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
File Edit Options Buffers Tools C++ Help
# include <iostream>
# include <sstream>
# include <exception>
# include "exception.hh"
MyException::
MyException( const char * Msg, int Line )
{
std::ostringstream oss;
oss << "Erreur ligne " << Line << " : "
<< Msg;
this->msg = oss.str();
}
virtual MyException::~MyException() throw()
{
}
virtual const char* MyException::what() throw()
{
return this->msg.c_str();
} |
voici le .hh
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
# include <iostream>
# include <sstream>
# include <exception>
class MyException : public std::exception
{
public:
MyException (const char *msg, int Line);
virtual ~MyException () throw ();
virtual const char *what() const throw();
private :
std::string msg;
}; |
et voici le main :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
# include <iostream>
# include <sstream>
# include <exception>
# include "exception.hh"
//on n'inclut que les delarations
int main()
{
try
{
throw MyException::MyException( "exception test", __LINE__ );
}
catch ( const std::exception & e )
{
std::cerr << e.what() << "\n";
}
} |
Franchement, je ne vois pas d'ou ça vient :
la derniere je coirs que je dois mettre l'etoile * apres MyEception:: car ça correspond a ce que je lui ai dit dans le .hh
sinon les deux premieres ça me dit rien !
please Help !
thx