bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_2 / eduincs / pgrm_025.cpp

pgrm_025.cpp (562B)


      1 /* WAP to demonstrate a class template with multiple parameters */
      2 
      3 #include <iostream>
      4 #include <string>
      5 using namespace std;
      6 
      7 template <typename T, typename U>
      8 class MyClass {
      9 public:
     10     T m_val1;
     11     U m_val2;
     12 
     13     MyClass(T val1, U val2) {
     14         m_val1 = val1;
     15         m_val2 = val2;
     16     }
     17 
     18     MyClass() : m_val1{}, m_val2{} {}
     19 };
     20 
     21 int main() {
     22     MyClass<int, string> myobj(5, "Hello");
     23     cout << myobj.m_val1 << " " << myobj.m_val2 << endl;
     24     MyClass<int, string> myobj2;
     25     cout << myobj2.m_val1 << " " << myobj2.m_val2 << endl;
     26     return 0;
     27 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror