Pergunta

I've seen a number of people with similar issues, but the solutions I've seen don't seem to fix my issue, so hopefully someone can see my issue and explain how to fix it or at least direct me to somewhere that can explain it.

Here is my code (at least the part that is breaking):

A.h

#ifndef A_H
#define A_H

enum myEnum {SOMEVALUE, OTHERVALUE};
class C;

class A
{
    public:
        virtual enum myEnum foo(C* c) = 0;
};

#endif // A_H

B.h

#include "A.h"

#ifndef B_H
#define B_H

class RuleConway : public A
{
    public:
        enum myEnum foo(C* c);
};

#endif // B_H

B.cpp

#include "B.h"
#include "C.h"

enum myEnum foo(C* c)
{
    // do things
    return SOMEVALUE;
}

When I try to compile my project, I get this:

undefined reference to `vtable for B'

Does anyone know why I'm getting this error or how to fix it?

Foi útil?

Solução

You have to implement the function as enum myEnum RuleConway::foo(C* c) in B.cpp. The way you're doing it now you are just defining a function called foo in B.cpp, not the B's member function.

Outras dicas

In B.cpp you should do

enum myEnum RuleConway::foo(C* c)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top