fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. template<class T>
  6. class A {
  7. protected:
  8. T m_i;
  9. virtual void m_set(T i)
  10. {
  11. m_i=i;
  12. };
  13. public:
  14. template<typename ... Args>
  15. void setParams( Args&&... params )
  16. {
  17. m_set(std::forward<Args>(params)...);
  18. }
  19. virtual void show()
  20. {
  21. cout << m_i << endl;
  22. }
  23. };
  24.  
  25.  
  26. template<class T, typename ... args>
  27. class B: public A<T> {
  28. protected:
  29. using A<T>::m_i;
  30. T m_j;
  31. virtual void m_set(T i, T j)
  32. {
  33. m_i=i;
  34. m_j=j;
  35. }
  36. public:
  37. virtual void show() override
  38. {
  39. cout << m_i << ':' << m_j << endl;
  40. }
  41. };
  42.  
  43.  
  44. int main() {
  45. auto a = new A<int>;
  46. a->setParams(22);
  47. a->show();
  48.  
  49. A<int>* b = new B<int>;
  50. a->setParams(22,23);
  51. a->show();
  52.  
  53. return 0;
  54. }
Compilation error #stdin compilation error #stdout 0s 15240KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘void A<T>::setParams(Args&& ...) [with Args = {int, int}; T = int]’:
prog.cpp:34:20:   required from here
prog.cpp:12:44: error: no matching function for call to ‘A<int>::m_set(int, int)’
  void setParams( Args&&... params ) { m_set(std::forward<Args>(params)...); }
                                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:9:15: note: candidate: void A<T>::m_set(T) [with T = int]
  virtual void m_set(T i) {m_i=i;};
               ^~~~~
prog.cpp:9:15: note:   candidate expects 1 argument, 2 provided
stdout
Standard output is empty