fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. class Foo
  6. {
  7. public:
  8. Foo(int things, float place) : m_thingList(things)
  9. {
  10. std::cout << "in Foo ctor" << std::endl;
  11. validatePlacePriorToAssignment(place);
  12. }
  13.  
  14. virtual ~Foo() {}
  15.  
  16. private:
  17. int m_thingList;
  18. float m_validatedPlace;
  19.  
  20. void validatePlacePriorToAssignment(float p)
  21. {
  22. // do stuff to validate place; if not valid, throw exception
  23. // else
  24. m_validatedPlace = p;
  25. }
  26. };
  27.  
  28. class Bar : public Foo
  29. {
  30. public:
  31. const float defaultPlace = 0.5;
  32. Bar(int stuff) : Foo(stuff, defaultPlace)
  33. {
  34. std::cout << "in Bar ctor" << std::endl;
  35. }
  36. };
  37.  
  38. int main()
  39. {
  40. int allTheThings;
  41.  
  42. try { Bar bar(allTheThings); }
  43. catch (...) { std::cout << "saddness" << std::endl; }
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
in Foo ctor
in Bar ctor