C++ static library, Can't inherited class

Asked by Ag

Hi, I'm creating a static library(I'm new to this) with C++ but failed to compile it, this happened when I try to inherited the class/object.

Here is the sources:

##Pin.h
######
class Pin : public Object {
public:
 virtual ~Pin(){}
protected:
 Pin_U Pin;
protected:
 virtual void Configure(void){}
public:
 virtual void Finalize(void);
 virtual void Configure(PinSettings_TPtr ptSettings){__unused_param(ptSettings);}
 virtual uint32_t Read(void) = 0;
 virtual int32_t ReadBit(int Bit) = 0;
 virtual void Write(uint32_t Val) = 0;
 virtual void WriteBit(int Bit, uint32_t Val) = 0;
};

##GPIO.h
#######
class GPIO : public Pin{
public:
 GPIO(Pin_U Pin){
  this->Pin = Pin;
 }

 GPIO(Pin_U Pin, GPIOSettings_TPtr ptSettings){
  this->Pin = Pin;
  this->Configure(ptSettings);
 }
 virtual ~GPIO(){

 }
private:
 GPIOSettings_T SettingsT;
public:
 void Configure(void);
 void Configure(PINSPEED_E Speed, GPIOMODE_E Mode);
 void Configure(GPIOSettings_TPtr ptSettings);
};

##GPIO.cpp
######## Implement GPIO.h's methods.
...
...
uint32_t
GPIO::Read(void){
 return(GPIOObj.Read(this->Pin));
}

int32_t
GPIO::ReadBit(int Bit){
 return(GPIOObj.ReadBit(this->Pin, Bit));
}

void
GPIO::Write(uint32_t Val){
 GPIOObj.Write(this->Pin, Val);
}
...
...

##After compiled, I got errors.
##########################

'Building file: ../System/IO/Pins/src/GPIO.cpp'
'Invoking: Cross ARM C++ Compiler'
arm-none-eabi-g++ -mcpu=cortex-m3 -mthumb -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall -Wextra -Wmissing-declarations -g3 -I"X:\Workspace\SpidexNS\Spidex.Micro.STD" -I"X:\Workspace\SpidexNS\Spidex.Micro.DDK" -I"X:\Workspace\SpidexNS\Spidex.Micro.HAL.ARM-CM3-ST32F10X" -I"X:\Workspace\SpidexNS\Spidex.Micro" -fno-exceptions -MMD -MP -MF"System/IO/Pins/src/GPIO.d" -MT"System/IO/Pins/src/GPIO.d" -c -o "System/IO/Pins/src/GPIO.o" "../System/IO/Pins/src/GPIO.cpp"

../System/IO/Pins/src/GPIO.cpp:12:20: error: no 'void GPIO::Finalize()' member function declared in class 'GPIO'
 GPIO::Finalize(void){
                    ^
../System/IO/Pins/src/GPIO.cpp:39:16: error: no 'uint32_t GPIO::Read()' member function declared in class 'GPIO'
 GPIO::Read(void){

... and so on.

Any idea?

Build System Information:
OS: Windows 7 Professional 64-bit SP2
IDE: Eclipse Keplar 32-64 bit + GNU ARM Eclipse plugin
Compiler: gcc-arm-none-eabi-4_8-2014q3-20140805-win32
Build tools: Codesourcery's make and rm

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Terry Guo
Solved:
Last query:
Last reply:
Revision history for this message
Terry Guo (terry.guo) said :
#1

I think you need to declare the GPIO::Read(void) function in the class GPIO firstly like below:

class GPIO : public Pin{
public:
     uint32_t Read(void);
}

then

uint32_t
GPIO::Read(void){
 return(GPIOObj.Read(this->Pin));
}

Revision history for this message
Ag (ajesicus-dev) said :
#2

But, it's already declared in parent class (class Pin), then it should be visible to the child class as well
 right!?

Revision history for this message
Best Terry Guo (terry.guo) said :
#3
Revision history for this message
Ag (ajesicus-dev) said :
#4

I see, but after I've tried out, it's took to another question. why the compiler doesn't gives any errors for the source code that don't re-declare and implement the parent methods.

Revision history for this message
Ag (ajesicus-dev) said :
#5

and also, why this re-declaration is only apply to method, why not also the property. because from what I see is, class's property is visible to child class automatically. Is this a c++ standard or something?

Revision history for this message
Terry Guo (terry.guo) said :
#6

My understanding is such restriction only happens to virtual function, won't happen to normal member function or properties. The reason behind this is that compiler has a special way to handle virtual function and its overridden.

Revision history for this message
Ag (ajesicus-dev) said :
#7

Ok, well then I'll take it as an answer. Thanks alot.

Revision history for this message
Ag (ajesicus-dev) said :
#8

Thanks Terry Guo, that solved my question.