I am getting compilation error. I am not able to figure it out whats the root cause.
I tried to comment on the constructor/desctructor of the Base class. And it worked. But uncommenting is causing a compilation error.
#include<iostream>
using namespace std;
class BaseException{
public:
BaseException();
virtual ~BaseException();
virtual void dumpmsg() = 0;
};
class DerivedException : public BaseException
{
public:
DerivedException():BaseException()
{
}
void dumpmsg() override
{
std::cout<< "Child class exception cuaght" << std::endl;
}
};
void h()
{
throw ( DerivedException() );
}
void g()
{
h();
}
void f()
{
g();
}
int main()
{
try{
f();
}
catch( BaseException &ex )
{
ex.dumpmsg();
}
}
Error Msg: In function ZN16DerivedExceptionC1Ev
: 15 undefined reference to BaseException::BaseException()
In function ZN16DerivedExceptionD1Ev
: 12 undefined reference to BaseException::~BaseException()
[Error] ld returned 1 exit status
Aucun commentaire:
Enregistrer un commentaire