fork download
  1. #include <iostream>
  2.  
  3.  
  4. class Multiplier
  5. {
  6. const int mFactor1;
  7. const int mFactor2;
  8. static void initializationLogic (int & a, int & b, const int c )
  9. {
  10. a = c * 5;
  11. b = a * 2;
  12. }
  13. public:
  14. Multiplier (const int & value1, const int & value2)
  15. : mFactor1(value1), mFactor2(value2)
  16. {};
  17. /*
  18.   //this constructor doesn't initialize the const members
  19.   Multiplier (const int & value)
  20.   {
  21.   initializationLogic(mFactor1,mFactor2, value);
  22.   };
  23.   */
  24. static Multiplier getMultiplierInstance (const int & value)
  25. {
  26. int f1, f2;
  27. initializationLogic(f1,f2, value);
  28. Multiplier obj(f1,f2);
  29. return obj;
  30. }
  31.  
  32. int multiply1(int value) const
  33. {
  34. return mFactor1 * value;
  35. }
  36.  
  37.  
  38. };
  39.  
  40. int main()
  41. {
  42. Multiplier myObj(2,3);
  43. std::cout << myObj.multiply1(3);
  44. Multiplier anotherObj = Multiplier::getMultiplierInstance(1);
  45. std::cout << anotherObj.multiply1(3);
  46. return 0;
  47. }
Success #stdin #stdout 0s 4276KB
stdin
1
2
10
42
11
stdout
615