Examveda

What will be the output of the following C++ code?
#include <iostream>
using namespace std; 
template<typename T>class clsTemplate
{
    public:
    T value;
    clsTemplate(T i)
    {
        this->value = i;
    }
void test()
{
    cout << value << endl;
}
};
class clsChild : public clsTemplate<char>
{
    public:
    clsChild(): clsTemplate<char>( 0 )
    {
    }
    clsChild(char c): clsTemplate<char>( c )
    {    
    }
void test2()
{
    test();
}
};
int main()
{
    clsTemplate <int> a( 42 );
    clsChild b( 'A' );
    a.test();
    b.test();
    return 0;
}

A. 42

B. A

C. 42
A

D. A
42

Answer: Option C


Join The Discussion

Related Questions on C plus plus miscellaneous

What is the difference between '++i' and 'i++' in C++?

A. None of the above

B. They both have the same effect

C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it

D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it