How to define a class method outside the class template in C++

1 Answer

0 votes
#include <iostream>
 
template<class T>
class Example {
public:
    T a, b;
    Example(T x, T y) : a(x), b(y) {}   // constructor
     
    void show();
};
 
template<class T>
void Example<T>::show() {
   std::cout << a << " " << b;
}
 
 
int main() {
    int x = 10;
    int y = 25;
     
    Example<int> obj(x, y);
     
    obj.show(); 
}
 
 
 
 
/*
run:
 
10 25
 
*/

 



answered Dec 6, 2022 by avibootz

Related questions

1 answer 200 views
1 answer 150 views
1 answer 139 views
1 answer 153 views
1 answer 166 views
166 views asked Dec 10, 2020 by avibootz
...