mercredi 25 mars 2015

Error: pure virtual method called terminate called without an active exception



class A
{
public:
static const int value1 = 1024;

enum AuthType
{
AuthType0 = 0;
AuthType1 = 1;
AuthType2 = 2;
};

virtual ~A() {}
virtual bool init() = 0;
virtual AuthType getAuthtype() = 0;
virtual int getSize() = 0;
}

class B : public A
{
public:
B();
bool init();
Authtype getAuthType();
int getSize();
private:
static std::atomic_uint s_ref;
uint8_t* m_cert;
}

B::B()
{
m_cert = nullptr;
}

bool B::init()
{
if(s_ref == 0)
{...}
s_ref++;
...
if(!m_cert)
{...}
return true;
}

A::AuthType
B::getAuthType()
{return AuthType1;}

int B::getSize()
{return ... }


I made a sample code for testing the action of these Classes. (Class A, and Class B)


The sample code is below.



int main(int argc, char* argv[])
{
B *pB = new B();
B ppB;
A::Authtype aa = A::AuthType0;
A::Authtype ab = A::Authtype0;

printf("%d", A::Authtype0);
printf("%d", pB->value1);

pB->init();
ppB.init();

aa = pB->getAuthtype();
printf("%d", aa);
...
return 0;
}


After init, I called getAuthtype(), and the error occurred. The error is below.


pure virtual method called terminate called without an active exception Aborted


I googled the error, and I found the reason. When a function which includes virtual keyword was called in constructor, this error may occur even if compile was good. But I don't think my problem is same as that. Could you guys find the cause of my problem?




Aucun commentaire:

Enregistrer un commentaire