Home » C++ Programming » Templates » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    template <class T>
    class N
    {
    public:
    N(int p): q(p) {}
    protected:
    int q;
    };
    template <class T>
    class M: public N<char>
    {
    public:
    M(): N<char>::N(50)
    {
    cout << q * 3 << endl;
    }
    };
    int main()
    {
    M<char> test;
    return 0;
    }
    1. 50
    2. 150
    3. Compilation Error
    4. Runtime Error
    5. None of these
Correct Option: B

In this program, We are passing the values and manipulating it by using the template inheritance.



Your comments will be displayed only after manual approval.