fork(1) download
  1. #include <fstream>
  2. #include <vector>
  3. #include <list>
  4. #include <math.h>
  5. #include <iostream>
  6. #include <memory>
  7. using namespace std;
  8.  
  9. template <class T>
  10. class Factory {
  11. protected:
  12. int num;
  13. public:
  14. Factory(int num) : num(num) {}
  15. virtual T * create() {
  16. return new T(num);
  17. }
  18. };
  19.  
  20. class Integer {
  21. int num;
  22. public:
  23. Integer(int num) : num(num) {}
  24. };
  25.  
  26. class Pair {
  27. int num1, num2;
  28. public:
  29. Pair(int num1, int num2) : num1(num1), num2(num2) {}
  30. };
  31.  
  32. class ExtendedFactory : public Factory<Pair> {
  33. protected:
  34. int num2;
  35. public:
  36. ExtendedFactory(int num1, int num2) : Factory(num1), num2(num2) {}
  37. virtual Pair * create() {
  38. return new Pair(num, 24);
  39. }
  40. };
  41.  
  42. int main()
  43. {
  44. Factory<Integer> ints(42);
  45. ints.create();
  46. return 0;
  47. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'T* Factory<T>::create() [with T = Pair]':
prog.cpp:47:1:   required from here
prog.cpp:16:25: error: no matching function for call to 'Pair::Pair(int&)'
         return new T(num);
                         ^
prog.cpp:29:5: note: candidate: Pair::Pair(int, int)
     Pair(int num1, int num2) : num1(num1), num2(num2) {}
     ^
prog.cpp:29:5: note:   candidate expects 2 arguments, 1 provided
prog.cpp:26:7: note: candidate: constexpr Pair::Pair(const Pair&)
 class Pair {
       ^
prog.cpp:26:7: note:   no known conversion for argument 1 from 'int' to 'const Pair&'
prog.cpp:26:7: note: candidate: constexpr Pair::Pair(Pair&&)
prog.cpp:26:7: note:   no known conversion for argument 1 from 'int' to 'Pair&&'
stdout
Standard output is empty