We can also pass user-defined types like class, structure, union as arguments to a function template. Consider the following function template which demonstrates passing a class as an argument: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #include <iostream> using namespace std; class Student { public: int age; string name; Student(int age, string name) { this->age = age; this->name = name; } }; template<class Type> void display(Type &obj) { cout<<“Name is: “<<obj.name<<endl; cout<<“Age is: “<<obj.age<<endl; } int main()
The post What are function templates with user defined types appeared first on Coding Security.
What are function templates with user defined types
read more
Tidak ada komentar:
Posting Komentar