Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,855 questions

51,776 answers

573 users

How to use class template with multiple and default parameters in C++

1 Answer

0 votes
#include <iostream>
 
template <class T, class U, class V = char>
class Example {
    private:
        T a;
        U b;
        V c;

   public:
        Example(T val1, U val2, V val3) : a(val1), b(val2), c(val3) {}  // constructor

    void print() {
        std::cout << "a = " << a << std::endl;
        std::cout << "b = " << b << std::endl;
        std::cout << "c = " << c << std::endl;
    }
};

int main() {
    Example<int, double> obj1(98, 3.14, 'w');
    obj1.print();

    Example<double, char, bool> obj2(5.891, 'p', true);
    obj2.print();
}
 
 
 
 
/*
run:
 
10 25
 
*/

 



answered Dec 6, 2022 by avibootz

Related questions

1 answer 192 views
1 answer 117 views
1 answer 161 views
2 answers 170 views
2 answers 249 views
1 answer 196 views
1 answer 169 views
...