Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to vtable [duplicate]

Tags:

c++

vtable

i have a class afporoills that helps find data in our memory managment module. (dont ask why such a wierd name i have no idea)

class afporoills{
    void** test(int pos);
};
void** afporoills::test(int pos){
    int x=(pos<<3)|1023*x;
    void** ret=(void**)x;
    if((int)ret%16) return this.test(pos+1);
    void* (*fp)(float, uint16__t)=x;
    ret=ret+(*fp)(1.0f, (uint16__t)pos);
    return ret;
}
int test(){
    afporoills afporoills14;
    return ((char*) (uint32_t) ((uint32_t) (void*) afporoills14.test(((((uint32_t)))((char*) (void*))1));

}

i keep getting

[Linker error] undefined reference to `vtable for afporoills`

but i have no idea what a vtable is!!! i havent used one so why are there errors for it?

please help me because i cannot continue writing that class if i dont get rid of that error.

also what do i have to do to make the test method turing-complete ?

like image 719
n00b Avatar asked Dec 02 '22 03:12

n00b


2 Answers

It is likely you got this error because you declared a virtual method in the Base class and did not define it, i.e no function body for the virtual function supplied in base class.

Try giving it some dummy body and compiling it might just work. I got this error just recently in a similar scenario that got fixed by providing a definition.

like image 69
SSinha Avatar answered Dec 05 '22 18:12

SSinha


The error indicates you didn't define your base class's virtual function and compiler can not find this function in the base class'es Virtual Method Table. Each derived class's object will have this Virtual method table that containing address to method defined in derived class.

To resolve your error, you may also define this function as PURE virtual function, means no function body in base class, for example:

virtual int handle(struct per_thread_traffic_log * pttl)=0;

like image 35
Houcheng Avatar answered Dec 05 '22 18:12

Houcheng