Pergunta

I am working on a project for school and I ran into a problem I am not sure how to solve. Here are bits of the code (not the whole classes) and the error message:

class CCPU
{
public:

                         CCPU                          ( uint8_t         * memStart,
                                                         uint32_t          pageTableRoot );
virtual                 ~CCPU                          ( void ) { }
virtual uint32_t         GetMemLimit                   ( void ) const = 0;
virtual bool             SetMemLimit                   ( uint32_t          pages ) = 0;
virtual bool             NewProcess                    ( void            * processArg,
                                                         void           (* entryPoint) ( CCPU *, void * ),
                                                         bool              copyMem ) = 0;

bool                     ReadInt                       ( uint32_t          address,
                                                         uint32_t        & value );
bool                     WriteInt                      ( uint32_t          address,
          m_PageTableRoot;
};

This is the class that inherits from the one above:

class CProcManager : public CCPU
{
public:

CProcManager( uint8_t* memStart,uint32_t pageTableRoot ) : CCPU(memStart, pageTableRoot) {}
virtual uint32_t         GetMemLimit                   ( void ) const;
virtual bool             SetMemLimit                   ( uint32_t          pages );
virtual bool             NewProcess                    ( void            * processArg,
                                                         void           (* entryPoint) ( CCPU *, void * ),
                                                         bool              copyMem );
static void              InitInfoPages                 (uint8_t * pages_mem);

};

And this would be the code calling the constructor:

CProcManager init_ccpu((uint8_t*)mem, 32/*just a test number*/);

The error message I get:

solution.o: In function `CProcManager::CProcManager(unsigned char*, unsigned int)':
/home/Jan/OSY/OSY-2/solution.cpp:19: undefined reference to `vtable for CProcManager'
solution.o: In function `CProcManager::~CProcManager()':
/home/Jan/OSY/OSY-2/solution.cpp:15: undefined reference to `vtable for CProcManager'
collect2: error: ld returned 1 exit status
make: *** [test1] Error 1

All the methods of CCPU and CProcManager classes are defined and I am not supposed to change the CCPU class (this class was provided in the project assignment). Can someone please explain to me where the problem lies(I guess its something with definitions)?

Foi útil?

Solução

This is most likely to mean that you forgot to implement one of the virtual functions declared in CProcManager - probably GetMemLimit. Or that you forgot to link with the translation unit containing that implementation.

Explanation: it looks like you're compiling with GCC. That compiler generates the vtable in the same translation unit as the first non-inline, non-pure virtual function declared in the class. If you don't implement that function, the vtable will be missing, giving that error.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top