Home » C++ Programming » Templates » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    template <class T>
    class Example
    {
    public:
    void putPri();
    static T ipub;
    private:
    static T ipri;
    };
    template <class T>
    void Example<T>::putPri()
    {
    cout << ipri++ << endl;
    }
    template <class T> T Example<T>::ipub = 1.5;
    template <class T> T Example<T>::ipri = 2.5;
    int main()
    {
    Example<int> a;
    Example<float> b;
    a.putPri();
    cout << a.ipub << endl;
    b.putPri();
    }
    1. 1.5
      2.5
    2. 2.5
      2
      1
    3. 2
      1
      2.5
    4. 2.5
      1.5
    5. None of these
Correct Option: C

In this program, We are passing the value of specified type and printing it by specialization.



Your comments will be displayed only after manual approval.