CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Our Services
Get 9,000 Interview Questions & Answers in an eBook.




Get it now !!
Send your Resume to 6000 Companies
Templates in C++ Interview Questions & Answers - Learning Mode
COOLINTERVIEW.COM C++ INTERVIEW QUESTIONS TEMPLATES IN C++ INTERVIEW QUESTIONS QUESTIONS & ANSWERS - LEARNING MODE

Templates in C++ Interview Questions & Answers - Learning Mode

Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type. A template is a blueprint or formula for creating a generic class or a function. Templates are a feature of the C++ programming language that allows functions and classes to operate with generic types. This allows a function or class to work on many different data types without being rewritten for each one.

Try Templates in C++ Interview Questions & Answers - Exam Mode

1

Sort By : Latest First | Oldest First | By Rating

Templates in C++ Interview Questions & Answers - Learning Mode
Try Templates in C++ Interview Questions & Answers - Exam Mode
Question: What is namespace?

Answer: Namespaces allow us to group a set of global classes, objects and/or functions under a name. To say<br>it somehow, they serve to split the global scope in sub-scopes known<br>as namespaces.<br><br>The form to use namespaces is:<br><br>namespace identifier { namespace-body }<br><br>Where identifier is any valid identifier and namespace-body is the set of classes, objects and<br>functions that are included within the namespace. For example:< Source: CoolInterview.com
Question: What is a template?

Answer: Templates allow to create generic functions that admit any data type as parameters and return value<br>without having to overload the function with all the possible data types. Until certain point they fulfill<br>the functionality of a macro. Its prototype is any of the two following ones:<br><br>template <class indetifier> function_declaration; template <typename indetifier><br>function_declaration;<br><br>The only difference between both pr Source: CoolInterview.com
Question: What is a friend function & its advantage?

Answer: if we want to write same function/s with the same body in two or more than two classes. We use the keyword friend in front of the that function declaration in the class. by using friend function we can reduce the size if program.<br>example:-<br>there are two classes EMPLOYEE and MANAGER.<br>and there is a function INCOMETEX. every employee and manager have to pay incometax.. in such case we use friend function infront of the INCOMTEX function. Source: CoolInterview.com
Question: How do you implement thread synchronization (Object.Wait, Notify,and CriticalSection) in C#?

Answer: You want the lock statement, which is the same as Monitor Enter/Exit:
lock(obj)
{
// code
}
translates to: try
{
CriticalSection.Enter(obj);
// code
}
finally
{
CriticalSection.Exit(obj);
} Source: CoolInterview.com
Question: How can you force instantiation of a template?



Answer: you can instantiat a template in two ways. 1. Implicit instantiation and 2. Explicit Instantion. implicit instatanitioan can be done by the following ways:<br><br>template <class T><br><br>class A<br><br>{<br><br>public: <br><br>A(){}<br><br>~A(){}<br><br>void x();<br><br>void z();<br><br>};<br><br>void main()<br><br>{<br><br>A<int> ai;<br Source: CoolInterview.com
Question: Can we have "Virtual Constructors"?



Answer: Yes we cannot have virtual constructors. But if the need arises, we can simulate the implementation of virtural constructor by calling a Init method from the constructor which, should be a virtual function. Source: CoolInterview.com
Question: When is a template a better solution than a base class?

Answer: When you are designing a generic class to contain or otherwise manage objects of other types, when the format and behavior of those other types are unimportant to their containment or management, and particularly when those other types are unknown (thus, the generosity) to the designer of the container or manager class. Source: CoolInterview.com
Question: What is the Standard Template Library (STL)?

Answer: A library of container templates approved by the ANSI committee for inclusion in the standard C++ specification.<br>A programmer who then launches into a discussion of the generic programming model, iterators, allocators, algorithms, and such, has a higher than average understanding of the new technology that STL brings to C++ programming. Source: CoolInterview.com
Question: Differentiate between a template class and class template.

Answer: Template class: A generic definition or a parameterized class not<br>instantiated until the client provides the needed information. It?s<br>jargon for plain templates.<br><br>Class template: A class template specifies<br>how individual classes can be constructed much like the way a class<br>specifies how individual objects can be constructed. It?s jargon for<br>plain classes. Source: CoolInterview.com
Question: What is a template?

Answer: Templates allow to create generic functions that admit any data type as parameters and return value without having to overload the function with all the possible data types. Until certain point they fulfill the functionality of a macro. Its prototype is any of the two following ones:<br><br><br>template <class indetifier> function_declaration; template <typename indetifier> function_declaration;<br>The only difference between both prototypes is the use of keyw Source: CoolInterview.com
Question: What is a template?




Answer: Template is used for creating generic functions as well as data members Source: CoolInterview.com
Question: When is a template a better solution than a base class?

Answer: When you are designing a generic class to contain or otherwise manage objects of other types, when the format and behavior of those other types are unimportant to their containment or management, and particularly when those other types are unknown (thus, the generosity) to the designer of the container or manager class. Source: CoolInterview.com

1



India News Network
Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal
Cache = 0.078125 Seconds