Template Arguments To Specify Policy Usage(C++ Programming ) Questions and Answers
Explanation:-
Answer: Option A. -> pointer to memberThe following are legal for non-type template parameters:integral or enumeration type, Pointer
to object or pointer to function, Reference to object or reference to function, Pointer to member.
Explanation:-
Answer: Option C. -> both a & bAnswer:d
Explanation:In this program, We are using the non-type template parameter to increment the value in the function template.
Output:
$ g++ farg4.cpp
$ a.out
2.1
3.1
4.1
Question 5.
1.
#include
2.
using namespace std;
3.
template
4.
class Test
5.
{
6.
public:
7.
Test()
8.
{
9.
};
10.
~Test()
11.
{
12.
};
13.
type Funct1(type Var1)
14.
{
15.
return Var1;
16.
}
17.
type Funct2(type Var2)
18.
{
19.
return Var2;
20.
}
21.
};
22.
int main()
23.
{
24.
Test Var1;
25.
Test Var2;
26.
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.
{
9.
};
10.
~Test()
11.
{
12.
};
13.
type Funct1(type Var1)
14.
{
15.
return Var1;
16.
}
17.
type Funct2(type Var2)
18.
{
19.
return Var2;
20.
}
21.
};
22.
int main()
23.
{
24.
Test Var1;
25.
Test Var2;
26.
cout
Explanation:-
Answer: Option D. -> 2003.123In this program, We are passing the value and returning it from template.
Output:
$ g++ farg3.cpp
$ a.out
2003.123