template class object c++ code example
Example 1: c++ template function
template <class T>
void swap(T & lhs, T & rhs)
{
T tmp = lhs;
lhs = rhs;
rhs = tmp;
}
Example 2: cpp how to create an object of template class
template class Graph<string>;
Example 3: c++ class template
#include <vector>
template <class T1, class T2, typename T3, typename T4 = int>
class MyClass
{
public:
MyClass() { }
private:
T1 data;
T2 anotherData;
T3 variable;
}
int main(int argc, char **argv)
{
std::vector<int> array(10);
MyClass<int> object();
return (0);
}