Templates
- Pick out the correct statement about string template.
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Every string template is used to replace the string with another string at runtime.
- What is a template?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
A template is a formula for creating a generic class
- 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();
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
In this program, We are passing the value of specified type and printing it by specialization.
- How many kinds of entities are directly parameterized in c++?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
C++ allows us to parameterize directly three kinds of entities through templates: types, constants, and templates.
- What is the output of this program?
#include <iostream>
using namespace std;
class BaseClass
{
public:
BaseClass( )
{
cout << "I ";
}
~BaseClass ( )
{
cout << " Mania";
}
};
class DerivedClass : public BaseClass
{
public:
DerivedClass ( )
{
cout << "Love ";
}
~DerivedClass ( )
{
cout << "Interview";
}
};
int main( )
{
DerivedClass x;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
In this program, We are printing the order of execution of constructor and destructor in the class.