Deck 16: Templates
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/27
العب
ملء الشاشة (f)
Deck 16: Templates
1
In implementing class template member functions,the functions are themselves templates.
True
2
The template prefix can be written template or template with the same results.
True
3
What if anything is wrong with the following code?
template
class A
{
public:
A();
...
private:
...
};
A::A()
{
//...
}
template
class A
{
public:
A();
...
private:
...
};
A
{
//...
}
The constructor A is a template function,hence it requires a template prefix:
template
A::A()
{
...
}
template
A
{
...
}
4
A non-template class can be derived from a class template instantiation.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
5
Templates can make available to the programmer the generality of algorithms that implementation with specific types conceals.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
6
Templates allow only parameterized types for class templates
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
7
It is preferable to separate implementation and specification in software.Hence,it is preferable to place a template class definition in a "header" file,the template implementation of the member functions in an implementation file.The implementation should be compiled separately and linked to the application.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
8
To instantiate and call,a template function requires special syntax.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
9
What problems with templates have you encountered,or have you been warned about by your instructor,with regard to your compiler's template facility?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
10
In the template prefix,template the keyword class means that the type parameter T must be of class type.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
11
It is possible to have more than one type parameter in a template definition.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
12
Templates provide an overloading of the function for every possible type that is consistent with the use in the template.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
13
Templates allow only parameterized types for functions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
14
A class template can be derived from a non-template class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
15
In the implementation of a class template function,the class name before the scope resolution operator is just the class name,with no additional syntax.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
16
Suppose the swapValues template is instantiated as follows:
int x = 2,y =3;
swapValues(x,y);
// use x and y
x = 4;y =5;
swapValues(x,y);
// use x and y
The compiler generates code for two copies of the swapValues template.
int x = 2,y =3;
swapValues(x,y);
// use x and y
x = 4;y =5;
swapValues(x,y);
// use x and y
The compiler generates code for two copies of the swapValues template.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
17
In the template prefix,template the identifier T is called a value parameter.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
18
In writing a class template,the function declarations within the class require special placement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
19
A class template cannot be derived from a class template.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
20
With regard to programming usage,consistency in coding is more important than optimality.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
21
What is wrong with the following function template (Other than the fact that it really does almost nothing)?
template
int f( int & x )
{
return x;
}
int main()
{
int y = 3,z;
z = f(y);
}
template
int f( int & x )
{
return x;
}
int main()
{
int y = 3,z;
z = f(y);
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
22
Discuss briefly,indicating whether mostly true or mostly false and justify:
A friend of a class is used exactly the same for template and non-template classes.
A friend of a class is used exactly the same for template and non-template classes.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
23
There are three absolute value functions defined in various header files.These are abs,fabs,and labs.Write a template function that subsumes all three of these functions into one template function.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
24
Define or characterize the template facility for C++.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
25
Which of the following template function definitions and invocations will not compile,if any? If not,why not?
Assume that classes have been declared with appropriate default constructors and assume that
//a)
template
A func( A x,A y){ return A();}
int main()
{
U u1,u2,u3;
u2 = func(u2,u3);
}
//b.
template
B func(){ return 1;}
int main()
{
T t;
t = func();
}
//c.
template
void func(C x,int * y){}
int main()
{
T t;
int i;
func( t,&i );
}
//d.
template
void func(D x,E y){}
int main()
{
T t;
U u;
func ( t,u );
}
Assume that classes have been declared with appropriate default constructors and assume that
//a)
template
A func( A x,A y){ return A();}
int main()
{
U u1,u2,u3;
u2 = func(u2,u3);
}
//b.
template
B func(){ return 1;}
int main()
{
T t;
t = func();
}
//c.
template
void func(C x,int * y){}
int main()
{
T t;
int i;
func( t,&i );
}
//d.
template
void func(D x,E y){}
int main()
{
T t;
U u;
func ( t,u );
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
26
Describe a strategy for writing template functions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
27
Describe the syntax for a function template.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck

