Go Down

Topic: Inheritance issue (Read 269 times) previous topic - next topic

Dave123

The base class contains an init() method, the extended class also has an init() that needs to call the base class init() then carry on doing what it's supposed to but it calls itself not the base class....

Software is Arduino v1

This is my base class 

Code: [Select]
class Autronic_SMCData
{
  public:
  int rpm;
  int vehicleSpeed;
  int wheelSpeed;
  int coolantTemp;
  int chargeTemp;
  int intakeTemp;
  int exhaustTemp;
  int manifoldPressure;
  int tps;
  int injTime;
  float ignAdv;
  float afr;
  float vBatt;

     void init()
    {
      rpm = 123;
      vehicleSpeed;
      wheelSpeed = 0;
      coolantTemp = 0;
      chargeTemp = 0;
      intakeTemp = 0;
      exhaustTemp = 0;
      manifoldPressure = 0;
      tps = 0;
      injTime = 0;
      ignAdv = 0;
      afr = 0;
      vBatt = 0;
  };
};



This extends the base class
Code: [Select]

class Autronic_SM2Data: public Autronic_SMCData
{
  public:
  int temp1;
  int temp2;
  int temp3;
  int temp4;
 
  void init()   
  {
    Autronic_SMCData:init();   // This does not call the method in the base class, it calls itself and eventually crashes the board
    temp1 = 0;
    temp2 = 0;
    temp3 = -2;   
    temp4 = 0;
  };
};


And this is how I declare and call it...
Code: [Select]

   Autronic_SM2Data sm2;
    sm2.init();


Does anything stand out as being the cause?

PaulS

Code: [Select]
    Autronic_SMCData:init();   // This does not call the method in the base class, it calls itself and eventually crashes the board

There should be two colons there, not one.

Dave123


Code: [Select]
    Autronic_SMCData:init();   // This does not call the method in the base class, it calls itself and eventually crashes the board

There should be two colons there, not one.


That's great, it works! I'm sure I tried that but hey ho!

Thanks

Go Up