jweinst1
8/21/2017 - 10:42 PM

refforprivassign.cpp

#include <iostream>

//using parent constructor in child class
//uses references to assign to param

class Doom {
  public:
  int a;
  short b;
  long c;
  int getA()
  {
    return a;
  }
  short getB()
  {
    return b;
  }
};

class A
{
protected:
  int amount;
private:
  long fuel;
  char g;
  Doom d;
public:
  A(long f, char g):  fuel(f), amount(0)
  {
    
  }
  long getFuel()
  {
    return fuel;
  }
  void setFuel(long& rfuel)
  {
    fuel = rfuel;
  }
  
  void setDoom(Doom& d)
  {
    d = d;
  }
};

class B: public A
{
public:
  B(long f, char g): A(f, g)
  {
  }
  int getAmount()
  {
    return amount;
  }
};

int main() {
  B test(500, 'j');
  long h = 200;
  Doom testtemp;
  test.setFuel(h);
  test.setDoom(testtemp);
  std::cout << "The fuel is: " << test.getFuel() << "\n";
}