pakis said:
I am having a problem of pure virtual function call in my project.
Can anyone explaine me the causes of pure virtual function calls
other than calling a virtual function in base class?
There are about 2 ways to get a pure virtual function call.
1. Calling a virtual function from the constructor or destructor of a class
where that virtual function is declared pure. Unlike C# or Java, C++ will
NOT call a virtual function overridden in a derived class when called from
the constructor or destructor of a base class.
<code>
stuct A
{
virtual void f() = 0;
A() { f(); }
~A() { f(); }
};
struct B : A
{
};
int main()
{
B b; // results in two pure calls
}
</code>
2. Calling a virtual function on a pointer to a deleted object where the
function was declared pure in the base class. This is actually undefined
behavior in C++, but under VC++ it will result in a pure virtual function
call if the function was in fact declared pure in the base class.
<code>
stuct A
{
virtual void f() = 0;
};
struct B : A
{
void f() {}
};
int main()
{
A* pa = new B();
delete pa;
pa->f();
}
</code>
Note that there are more complex variants of both of these cases, but
they'll boil down to one of these two.
-cd