-1

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)
{
}
jscs
  • 63,694
  • 13
  • 151
  • 195
Raj iOS
  • 1,047
  • 1
  • 9
  • 20
  • 2
    Seems to me your `drawAabb` implementation (and several others) is missing the `debugDrawer::` specifier. – DCoder Aug 13 '12 at 06:52
  • 1
    These functions are virtual function which is implemented to avoid "Allocating an object for abstact class type". I have implemented all functions I suppose. Its empty but do have a definition – Raj iOS Aug 13 '12 at 09:38
  • No, you implemented global functions with the same name, not class member functions. See [maxbc's answer](http://stackoverflow.com/a/11931617/1233508). – DCoder Aug 13 '12 at 09:45
  • Ok I renamed the definitions as maxbc said. It works. It required a detailed explanation to understand. Anyway thanks for your comments – Raj iOS Aug 13 '12 at 10:16

2 Answers2

1

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.

maxbc
  • 949
  • 1
  • 8
  • 18
0

Keep virtual at the beginning and add override at the end, so your functions are mapped to the ones declared in Bullet Physics, such as:

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

LastBlow
  • 617
  • 9
  • 16