Derivation And Templates(C++ Programming ) Questions and Answers
Question 4.
1.
#include
2.
using namespace std;
3.
template
4.
class Test
5.
{
6.
public:
7.
Test();
8.
~Test();
9.
type Data(type);
10.
};
11.
template
12.
type Test::Data(type Var0)
13.
{
14.
return Var0;
15.
}
16.
template
17.
Test::Test()
18.
{
19.
}
20.
template
21.
Test::~Test()
22.
{
23.
}
24.
int main(void)
25.
{
26.
Test Var3;
27.
cout
What is the output of this program?
1.
#include
2.
using namespace std;
3.
template
4.
class Test
5.
{
6.
public:
7.
Test();
8.
~Test();
9.
type Data(type);
10.
};
11.
template
12.
type Test::Data(type Var0)
13.
{
14.
return Var0;
15.
}
16.
template
17.
Test::Test()
18.
{
19.
}
20.
template
21.
Test::~Test()
22.
{
23.
}
24.
int main(void)
25.
{
26.
Test Var3;
27.
cout
Explanation:-
Answer: Option A. -> kIn this program, We are passing the values and printing it by using template inheritance.
Output:
$ g++ dert3.cpp
$ a.out
k
Explanation:-
Answer: Option B. -> 200In this program, We are passing the values and manipulating it by using the template inheritance.
Output:
$ g++ dert2.cpp
$ a.out
200