(presumed) inheritance issue when wrtting a library [FIXED]

Working libraries, libraries being ported and related hardware
Post Reply
logd32
Posts: 20
Joined: Thu Sep 07, 2017 8:41 pm

(presumed) inheritance issue when wrtting a library [FIXED]

Post by logd32 » Mon Dec 04, 2017 2:55 pm

Hi,
I am facing a weird issue when writing a library, i suspect it is related to inheritence but i am not sure, does anyone know what the problem could be?
it is declared as follow:

Code: Select all

DriverHal device( &callbacks );

An throws this error

Code: Select all

error : variable 'DriverHal device' has initializer but incomplete type

Code: Select all

//in main.cpp

void OnActionDone( void );
DeviceCallbacks_t callbacks ={ 
    &OnActionDone,                  
};

DriverHal device( &callbacks );   

void setup() {
  //device.Init( );
}

void loop() {
}


//in driver_hal.cpp
DriverHal::DriverHal(DeviceCallbacks_t *callbacks):Driver( callbacks ){

};


//in driver_hal.h
class DriverHal : public Driver
{
public:
    DriverHal(DeviceCallbacks_t *callbacks);
    virtual ~DriverHal( void );
};


//in driver.cpp
void Driver::Init( void ) // not relevant for the issue
{

}


//in driver.h
class Driver : public Device
{
public:
    Driver( DeviceCallbacks_t *callbacks ): Device( callbacks ) 
    {

    }

    virtual ~Driver( )
    {
      
    }
    
    void Init( void );
};   


//in device.h
typedef struct
{
    void ( *OnActionDone )( void );                               
}DeviceCallbacks_t;


class Device
{
protected:
    void ( *OnActionDone )( void );
public:
    Device( DeviceCallbacks_t *callbacks )
    {
        this->OnActionDone = callbacks->OnActionDone;
    }
    virtual ~Device( void ){ };
};  




The ready to run test sketch is attached
Attachments
INHERITANCE_ISSUE.zip
(2.03 KiB) Downloaded 8 times
Last edited by logd32 on Tue Dec 05, 2017 4:49 pm, edited 1 time in total.

lacklustrlabs
Posts: 13
Joined: Fri May 05, 2017 12:35 pm

Re: (presumed) inheritance issue when wrtting a library

Post by lacklustrlabs » Mon Dec 04, 2017 9:15 pm

First line in INHERITANCE_ISSUE.ino should read:

Code: Select all

#include "driver_hal.h"
An include guard in device.h would not hurt. I tend to use "#pragma once" more and more in my sketches..

Good luck!

logd32
Posts: 20
Joined: Thu Sep 07, 2017 8:41 pm

Re: (presumed) inheritance issue when wrtting a library

Post by logd32 » Tue Dec 05, 2017 4:48 pm

Well spoteed, the problem was indeed the missing include of driver_hal.h in the sketch, thank you!

Post Reply