Search code examples
c++vtable

Allocating an object for abstact class type if not implemented and missing vtable error if declared and defined


I have to inherit an abstract base class which has 5 virtual functions. If i dont implement those 5 functions I get "Allocating an object for abstact class type if not implemented".

When i declare and implement in derived class I get "Undefined symbols for architecture i386: "vtable for debugDrawer", referenced from: debugDrawer::debugDrawer() in debugDrawer.o NOTE: a missing vtable usually means the first non-inline virtual member function has no definition."

class btIDebugDraw- base class from bullet physics library is as follows

class   btIDebugDraw
{
virtual void    drawContactPoint(const btVector3& PointOnB,const btVector3&    normalOnB,btScalar distance,int lifeTime,const btVector3& color)=0;

virtual void    reportErrorWarning(const char* warningString) = 0;

virtual void    draw3dText(const btVector3& location,const char* textString) = 0;

virtual void    setDebugMode(int debugMode) =0;

virtual int     getDebugMode() const = 0;

virtual void drawAabb(const btVector3& from,const btVector3& to,const btVector3& color)
}

Derived Class debugDrawer.h

class debugDrawer : public btIDebugDraw{
public:
debugDrawer();
void    drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar   distance,int lifeTime,const btVector3& color);    
void    reportErrorWarning(const char* warningString);    
void    draw3dText(const btVector3& location,const char* textString);
void    setDebugMode(int debugMode);    
int     getDebugMode() const;    
void drawAabb(const btVector3& from,const btVector3& to,const btVector3& color);

void  drawLine(const btVector3& from,const btVector3& to,const btVector3& color);
};

Derived Class debugDrawer.mm file (I'm using objective c, so its .mm file)

debugDrawer::debugDrawer(){

}

void debugDrawer::drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
{
    float tmp[ 6 ] = { from.getX(), from.getY(), from.getZ(),
        to.getX(), to.getY(), to.getZ() };        
    glPushMatrix();
    {         
        glColor4f(color.getX(), color.getY(), color.getZ(), 1.0f);         
        glVertexPointer( 3,
                        GL_FLOAT,
                        0,
                        &tmp );

        glPointSize( 5.0f );
        glDrawArrays( GL_POINTS, 0, 2 );
        glDrawArrays( GL_LINES, 0, 2 );
    }
    glPopMatrix();      

    }

void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color){

}
void    reportErrorWarning(const char* warningString) {

}
void draw3dText(const btVector3& location,const char* textString) {

}
void setDebugMode(int debugMode){

}
int getDebugMode() {
return 0;
}
void drawAabb(const btVector3& from,const btVector3& to,const btVector3& color)
{
}

Solution

  • Don't forget the class specifications in your drawContactPoint() definition: it is the first function of the vtable (see definition of btIDebugDraw) and has no definition, so vtable is missing (as the note says).

    void debugDrawer::drawContactPoint(...) {}
    

    instead of

    void drawContactPoint(...) {}
    

    You will then get normal unimplemented functions errors, and you will have to repeat those changes to all the other functions.