Pages: [1]   Go Down
Author Topic: Inheritance issue  (Read 213 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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:
   Autronic_SM2Data sm2;
    sm2.init();

Does anything stand out as being the cause?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46077
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    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
Logged

Pages: [1]   Go Up
Jump to: