1. In C++, what is the difference between method overloading andmethod overwriting?
Overloading a method (or function) in C++ is the ability for functions ofthe same name to be defined as long as these methods have different signatures(different set of parameters). Method overwriting is the ability of theinherited class rewriting the virtual method of the base class.
2. What methods can be overwritten in Java? In C++ terminology,all public methods in Java are virtual. Therefore, all Java methods can beoverwritten in subclasses except those that are declared final, static, andprivate.
3. In C, What is the difference between a staticvariable and global variable?
A static variable declared outside of any function is accessible only toall the functions defined in the same file (as the static variable). However, aglobal variable can be accessed by any function (including the ones fromdifferent files).
4. In C, why is the void pointer useful?
The void pointer is useful becuase it is a generic pointer that anypointer can be cast into and back again without loss of information.
5. What are the defining traits of anobject-oriented language?
The defining traits of an object-oriented langauge are:
· encapsulation
· inheritance
· polymorphism
What is pure virtual function?
A class is made abstract by declaring one or more of its virtual functionsto be pure. A pure virtual function is one with an initializer of = 0 in itsdeclaration
A class is made abstract by declaring one or more of its virtual functionsto be pure. A pure virtual function is one with an initializer of = 0 in itsdeclaration
Q. Write a Struct Time where integer m, h, s are its members
struct Time
{
int m;
int h;
int s;
};
struct Time
{
int m;
int h;
int s;
};
ow do you traverse a Btree in Backward in-order?
Process the node in the right subtree
Process the root
Process the node in the left subtree
Process the node in the right subtree
Process the root
Process the node in the left subtree
Q. What is the two main roles of Operating System?
As a resource manager
As a virtual machine
As a resource manager
As a virtual machine
Q. In the derived class, which data member of the base class arevisible?
In the public and protected sections.
In the public and protected sections.
1. How do you write a function that can reverse a linked-list? (CiscoSystem)
void reverselist(void)
{
if(head==0)
return;
if(head->next==0)
return;
if(head->next==tail)
{
head->next = 0;
tail->next = head;
}
else
{
node* pre = head;
node* cur = head->next;
node* curnext = cur->next;
head->next = 0;
cur->next = head;
for(; curnext!=0; )
{
cur->next = pre;
pre = cur;
cur = curnext;
curnext = curnext->next;
}
curnext->next = cur;
}
}
2. What is polymorphism?
Polymorphism is the idea that a base class can be inherited by severalclasses. A base class pointer can point to its child class and a base classarray can store different child class objects.
3. How do you find out if a linked-list has an end? (i.e. the list isnot a cycle)
You can find out by using 2 pointers. One of them goes 2 nodes each time.The second one goes at 1 nodes each time. If there is a cycle, the one thatgoes 2 nodes each time will eventually meet the one that goes slower. If thatis the case, then you will know the linked-list is a cycle.
4. How can you tell what shell you are running on UNIX system?
You can do the Echo $RANDOM. It will return a undefined variable if youare from the C-Shell, just a return prompt if you are from the Bourne shell,and a 5 digit random numbers if you are from the Korn shell. You could also doa ps -l and look for the shell with the highest PID.
5. What is Boyce Codd Normal form?
A relation schema R is in BCNF with respect to a set F of functionaldependencies if for all functional dependencies in F+ of the form a->b,where a and b is a subset of R, at least one of the following holds:
· a->b is a trivial functional dependency (b isa subset of a)
· a is a superkey for schema R
Q: What is the difference between Stack and Queue?
A: Stack is a Last In First Out (LIFO) data structure.
Queue is a First In First Out (FIFO) data structure
Q: Write a fucntion that will reverse a string. (Microsoft)
A: char *strrev(char *s)
{
int i = 0, len = strlen(s);
char *str;
if ((str = (char *)malloc(len+1)) == NULL) /*cannot allocate memory */
err_num = 2;
return (str);
}
while(len)
str[i++]=s[–len];
str[i] = NULL;
return (str);
}
Q: What is the software Life-Cycle?
A: The software Life-Cycle are
1) Analysis and specification of the task
2) Design of the algorithms and data structures
3) Implementation (coding)
4) Testing
5) Maintenance and evolution of the system
6) Obsolescence
Q: What is the difference between a Java application and a Java applet?
A: The difference between a Java application and a Java applet is that a
Java application is a program that can be executed using the Java
interpeter, and a JAVA applet can be transfered to different networks
and executed by using a web browser (transferable to the WWW).
Q: Name 7 layers of the OSI Reference Model? (from Cisco)
A: -Application layer
-Presentation layer
-Session layer
-Transport layer
-Network layer
-Data Link layer
-Physical layer
Q1 What are the advantages and disadvantages of B-star trees overBinary trees? (Asked by Motorola people)
A1 B-star trees have better data structure and are faster in search thanBinary trees, but it’s harder to write codes for B-start trees.
Q2 Write the psuedo code for the Depth first Search.(Asked byMicrosoft)
A2
dfs(G, v) //OUTLINE
Mark v as "discovered"
For each vertex w such that edge vw is in G:
If w is undiscovered:
dfs(G, w); that is, explore vw, visit w, explore from there
as much as possible, and backtrack from w to v.
Otherwise:
"Check" vw without visiting w.
Mark v as "finished".
Mark v as "discovered"
For each vertex w such that edge vw is in G:
If w is undiscovered:
dfs(G, w); that is, explore vw, visit w, explore from there
as much as possible, and backtrack from w to v.
Otherwise:
"Check" vw without visiting w.
Mark v as "finished".
Q3 Describe one simple rehashing policy.(Asked by Motorola people)
A3 The simplest rehashing policy is linear probing. Suppose a key Khashes to location i. Suppose other key occupies H[i]. The following functionis used to generate alternative locations:
rehash(j) = (j + 1) mod h
where j is the location most recently probed. Initially j = i, the hashcode for K. Notice that this version of rehash does not depend on K.
Q4 Describe Stacks and name a couple of places where stacks areuseful. (Asked by Microsoft)
A4 A Stack is a linear structure in which insertions and deletions arealways made at one end, called the top. This updating policy is called last in,first out (LIFO). It is useful when we need to check some syntex errors, suchas missing parentheses.
Q5 Suppose a 3-bit sequence number is used in the selective-rejectARQ, what is the maximum number of frames that could be transmitted at a time?(Asked by Cisco)
A5 If a 3-bit sequence number is used, then it could distinguish 8different frames. Since the number of frames that could be transmitted at atime is no greater half the numner of frames that could be distinguished by thesequence number, so at most 4 frames can be transmitted at a time.
1.Question: Suppose that data is an array of 1000 integers. Write asingle function call that will sort the 100 elements data [222] through data[321].
Answer: quicksort ((data + 222), 100);
Answer: quicksort ((data + 222), 100);
2.Question: Which recursive sorting technique always makes recursivecalls to sort subarrays that are about half size of the original array?
Answer: Mergesort always makes recursive calls to sort subarrays that areabout half size of the original array, resulting in O(n log n) time.
Answer: Mergesort always makes recursive calls to sort subarrays that areabout half size of the original array, resulting in O(n log n) time.
3.Question: What is the difference between an external iterator and aninternal iterator? Describe an advantage of an external iterator.
Answer: .An internal iterator is implemented with member functions of theclass that has items to step through. .An external iterator is implemented as aseparate class that can be "attach" to the object that has items tostep through. .An external iterator has the advantage that many differenceiterators can be active simultaneously on the same object.
Answer: .An internal iterator is implemented with member functions of theclass that has items to step through. .An external iterator is implemented as aseparate class that can be "attach" to the object that has items tostep through. .An external iterator has the advantage that many differenceiterators can be active simultaneously on the same object.
4.Question: Why are arrays usually processed with for loop?
Answer: The real power of arrays comes from their facility of using anindex variable to traverse the array, accessing each element with the sameexpression a[i]. All the is needed to make this work is a iterated statement inwhich the variable i serves as a counter, incrementing from 0 to a.length -1.That is exactly what a loop does.
Answer: The real power of arrays comes from their facility of using anindex variable to traverse the array, accessing each element with the sameexpression a[i]. All the is needed to make this work is a iterated statement inwhich the variable i serves as a counter, incrementing from 0 to a.length -1.That is exactly what a loop does.
5.Question: What is an HTML tag?
Answer: An HTML tag is a syntactical construct in the HTML language thatabbreviates specific instructions to be executed when the HTML script is loadedinto a Web browser. It is like a method in Java, a function in C++, a procedurein Pascal, or a subroutine in FORTRAN.
Answer: An HTML tag is a syntactical construct in the HTML language thatabbreviates specific instructions to be executed when the HTML script is loadedinto a Web browser. It is like a method in Java, a function in C++, a procedurein Pascal, or a subroutine in FORTRAN.
: How do you link a C++ program to C functions?
A: By using the extern "C" linkage specification around the Cfunction declarations.
Q: Explain the scope resolution operator.
A: It permits a program to reference an identifier in the global scopethat has been hidden by another identifier with the same name in the localscope.
Q: What are the differences between a C++ struct and C++ class?
A: The default member and base-class access specifiers are different.
Q: How many ways are there to initialize an int with a constant?
A: Two.
There are two formats for initializers in C++ as shown in the examplethat follows. The first format uses the traditional C notation. The secondformat uses constructor notation.
int foo = 123;
int bar (123);
Q: How does throwing and catching exceptions differ from using setjmp andlongjmp?
A: The throw operation calls the destructors for automatic objectsinstantiated since entry to the try block.
Q: What is your reaction to this line of code?
delete this;
A: It’s not a good practice.
Q: What is a default constructor?
A: A constructor that has no arguments.
Q: What is a conversion constructor?
A: A constructor that accepts one argument of a different type.
Q: What is the difference between a copy constructor and an overloadedassignment operator?
A: A copy constructor constructs a new object by using the content of theargument object. An overloaded assignment operator assigns the contents of anexisting object to another existing object of the same class.
Q: When should you use multiple inheritance?
A: There are three acceptable answers: "Never,""Rarely," and "When the problem domain cannot be accuratelymodeled any other way."
Q: What is a virtual destructor?
A: The simple answer is that a virtual destructor is one that is declaredwith the virtual attribute.
Q: Explain the ISA and HASA class relationships. How would you implementeach in a class design?
A: A specialized class "is" a specialization of another classand, therefore, has the ISA relationship with the other class. An Employee ISAPerson. This relationship is best implemented with inheritance. Employee isderived from Person. A class may have an instance of another class. Forexample, an employee "has" a salary, therefore the Employee class hasthe HASA relationship with the Salary class. This relationship is bestimplemented by embedding an object of the Salary class in the Employee class.
Q: When is a template a better solution than a base class?
A: When you are designing a generic class to contain or otherwise manageobjects of other types, when the format and behavior of those other types areunimportant to their containment or management, and particularly when thoseother types are unknown (thus, the genericity) to the designer of the containeror manager class.
Q: What is a mutable member?
A: One that can be modified by the class even when the object of theclass or the member function doing the modification is const.
Q: What is an explicit constructor?
A: A conversion constructor declared with the explicit keyword. Thecompiler does not use an explicit constructor to implement an impliedconversion of types. It’s purpose is reserved explicitly for construction.
Q: What is the Standard Template Library?
A: A library of container templates approved by the ANSI committee forinclusion in the standard C++ specification.
A programmer who then launches into a discussion of the genericprogramming model, iterators, allocators, algorithms, and such, has a higherthan average understanding of the new technology that STL brings to C++programming.
Q: Describe run-time type identification.
A: The ability to determine at run time the type of an object by usingthe typeid operator or the dynamic_cast operator.
Q: What problem does the namespace feature solve?
A: Multiple providers of libraries might use common global identifierscausing a name collision when an application tries to link with two or moresuch libraries. The namespace feature surrounds a library’s externaldeclarations with a unique namespace that eliminates the potential for thosecollisions.
This solution assumes that two library vendors don’t use the samenamespace identifier, of course.
Q: Are there any new intrinsic (built-in) data types?
A: Yes. The ANSI committee added the bool intrinsic type and its true andfalse value keywords.
What is a Make file?(Fujitsu)
Ans: Make file is a utility in Unix to help compile large programs. Ithelps by only compiling the portion of the program that has been changed.
Ans: Make file is a utility in Unix to help compile large programs. Ithelps by only compiling the portion of the program that has been changed.
2. What is deadlock?(Novell)
Deadlock is a situation when two or more processes prevent each other fromrunning.Example: if T1 is holding x and waiting for y to be free and T2 holdingy and waiting for x to be free deadlock happens.
Deadlock is a situation when two or more processes prevent each other fromrunning.Example: if T1 is holding x and waiting for y to be free and T2 holdingy and waiting for x to be free deadlock happens.
emaphore?(Novell)
Semaphore is a special variable, it has two methods: up and down. Semaphoreperforms atomic operations, which means ones a semaphore is called it can notbe inturrupted.
Semaphore is a special variable, it has two methods: up and down. Semaphoreperforms atomic operations, which means ones a semaphore is called it can notbe inturrupted.
4. Is C an Object Oriented language?(Microsoft)
C is not an Object Oriented language, but limited Object Orientedprogramming can be done in C.
C is not an Object Oriented language, but limited Object Orientedprogramming can be done in C.
5. What is difference between C++ and Java?
C++ has pointers Java does not.
C++ has pointers Java does not.
Java is platform independent C++ is not.
Java has garbage collection C++ does not.
Q1: Could you tell something about the Unix System Kernel? (from ITCO)
A1: The kernel is the heart of the UNIX openrating system, it’sreponsible for controlling the computer’s resouces and scheduling user jobs sothat each one gets its fair share of resources.
Q2: What are each of the standard files and what are they normallyassociated with? (from ITCO )
A2: They are the standard input file, the standard output file and thestandard error file. The first is usually associated with the keyboard, thesecond and third are usually associated with the terminal screen.
Q3: Detemine the code below, tell me exectly how many times is theoperation sum++ performed ? (from ITCO )
for ( i = 0; i < 100; i++ )
for ( j = 100; j > 100 - i; j–)
sum++;
A3: (99 * 100)/2 = 4950
The sum++ is performed 4950 times.
for ( j = 100; j > 100 - i; j–)
sum++;
A3: (99 * 100)/2 = 4950
The sum++ is performed 4950 times.
Q4: Give 4 examples which belongs application layer in TCP/IParchitecture? (from CISCO )
A4: FTP, TELNET, HTTP and TFTP
Q5: What’s the meaning of ARP in TCP/IP? (from CISCO )
A5: The "ARP" stands for Address Resolution Protocol. The ARPstandard defines two basic message types: a request and a response. a requestmessage contains an IP address and requests the corresponding hardware address;a replay contains both the IP address, sent in the request, and the hardwareaddress.
Q: Do you have a basic understanding of C and C++ and theirsimilarities and differences?
A: Yes.
If the answer is "yes," proceed and plan to ask all thequestions in the first group. If not, the interview for a C++ programmer's jobshould be over, and you should be talking about other employment opportunities.
Q: Have you participated in the design of C++ classes to supportan application's problem domain?
A: Yes or No.
If the answer is "yes," plan to include the questions in thesecond group. Applicants usually want to describe the details of the systemsthey have designed. Pay attention if you understand the nature of theapplication. If not, pretend to pay attention. If they have not actually done anyclass design, ask if they think they understand it. If so, include the secondset of questions.
Q: Do you keep up with what the ANSI C++ Standards committee isdoing?
A: Yes or No.
Most people do not. Few people have the time. But occasionally there isthat rare soul who reads all the magazines and books, owns a copy of the draftstandard, and regularly tracks the C++ news groups on the net. If an applicantclaims to be one of them, include the third group of questions in yourinterrogation
Q: How do you link a C++ program to C functions?
A: By using the extern "C" linkage specification aroundthe C function declarations.
Programmers should know about mangled function names and type-safelinkages. Then they should explain how the extern "C" linkagespecification statement turns that feature off during compilation so that thelinker properly links function calls to C functions. Another acceptable answeris "I don't know. We never had to do that." Merely describing what alinker does indicates that the programmer does not understand the issue thatunderlies the question.
Q: Explain the scope resolution operator.
A: It permits a program to reference an identifier in the globalscope that has been hidden by another identifier with the same name in thelocal scope.
The answer can get complicated. However, it should start with"::". If the programmer is well into the design or use of classesthat employ inheritance you might hear a lot about overriding member functionoverrides to explicitly call a function higher in the hierarchy. That's good toknow, but ask specifically about global scope resolution. You're looking for adescription of C++'s ability to override the particular C behavior whereidentifiers in the global scope are always hidden by like identifiers in alocal scope.
Q: What are the differences between a C++ struct and C++ class?
A: The default member and base-class access specifiers aredifferent.
This is one of the commonly misunderstood aspects of C++. Believe it ornot, many programmers think that a C++ struct is just like a C struct,while a C++ class has inheritance, access specifiers, member functions,overloaded operators, and so on. Some of them have even written books aboutC++. Actually, the C++ struct has all the features of the class.The only differences are that a struct defaults to public member accessand public base-class inheritance, and a class defaults to the privateaccess specifier and private base-class inheritance. Getting this questionwrong does not necessarily disqualify an applicant. Getting it right is adefinite plus.
Saying, "I don't know" is definitely the wrong answer. Iadvance an unusual position about this. C++ programmers should at least believethat they know the differences, even when they are wrong about them. Getting itwrong is, therefore, right. You can explain the true difference in theinterview and advance the programmer's knowledge. If they disagreevociferously, you have an opportunity to observe how they handle contentiousdebate when they are wrong and don't know it yet.
Q: How many ways are there to initialize an int with aconstant?
A: Two.
There are two formats for initializers in C++ as shown in the examplethat follows. The first format uses the traditional C notation. The secondformat uses constructor notation.
int foo = 123;
int bar (123);
It's acceptable when a programmer does not know about the secondnotation, although they should certainly know about the first one. Manyold-timer C programmers who made the switch to C++ never use the second idiom,although some wise heads of C++ profess to prefer it. If your applicant isquick with the right answer, that's a good sign.
Q: How does throwing and catching exceptions differ from using setjmpand longjmp?
A: The throw operation calls the destructors for automatic objectsinstantiated since entry to the try block.
Exceptions are in the mainstream of C++ now, so most programmers, if theyare familiar with setjmp and longjmp, should know the difference.Both idioms return a program from the nested depths of multiple function callsto a defined position higher in the program. The program stack is"unwound" so that the state of the program, with respect to function callsand pushed arguments, is restored as if the calls had not been made. C++exception handling adds to that behavior the orderly calls to the destructorsof automatic objects that were instantiated as the program proceeded fromwithin the try block toward where the throw expression isevaluated.
Applicants might think you want to hear about the notational differencesbetween the two idioms. Let them proceed to explain the syntax of tryblocks, catch exception handlers, and throw expressions. Then askthem specifically what happens in a throw that does not happen in a longjmp.Their answer should reflect an understanding of the behavior described in theprevious answer.
One valid reason for not knowing about exception handling is that theapplicant's experience is exclusively with older C++ compilers that do notimplement exception handling. I would prefer that they have at least heard ofexception handling, though. Another marginally acceptable reason is that theirformer supervisors and designers did not mandate and specify the use ofexception handling in programs. In that case get the names of those supervisorsand designers so that you can decline their applications if they should comea'knocking.
It is not unusual for C and C++ programmers to be unfamiliar with setjmp/
longjmp. Those constructs are not particularly intuitive. A C programmerwho has written recursive descent parsing algorithms will certainly be familiarwith setjmp/longjmp. Others might not, and that's acceptable. Inthat case, they won't be able to discuss how setjmp/longjmpdiffers from C++ exception handling, but let the interview turn into adiscussion of C++ exception handling in general. That conversation will reveala lot about a programmer's understanding of C++.
longjmp. Those constructs are not particularly intuitive. A C programmerwho has written recursive descent parsing algorithms will certainly be familiarwith setjmp/longjmp. Others might not, and that's acceptable. Inthat case, they won't be able to discuss how setjmp/longjmpdiffers from C++ exception handling, but let the interview turn into adiscussion of C++ exception handling in general. That conversation will reveala lot about a programmer's understanding of C++.
Questionsfor Class Designers
The second group of questions explores the applicant's knowledge of classdesign. There are eight questions. Five out of eight is a good score.
Q: What is your reaction to this line of code?
delete this;
A: It's not a good practice.
Many applicants will look at you like you are nuts. They've never heardof this usage, and it's never occurred to them. That's a very good answer.Perhaps they will try to explain the behavior of the statement. Ask them tocontemplate its consequences. Two quite acceptable reactions are, "Don'tdo it," and "Don't do it unless you really know what you are doingand you are a masochist."
A good programmer will insist that you should absolutely never use thestatement if the class is to be used by other programmers and instantiated asstatic, extern, or automatic objects. That much should be obvious.
The code has two built-in pitfalls. First, if it executes in a memberfunction for an extern, static, or automatic object, the program will probablycrash as soon as the delete statement executes. There is no portable wayfor an object to tell that it was instantiated on the heap, so the class cannotassert that its object is properly instantiated. Second, when an object commitssuicide this way, the using program might not know about its demise. As far asthe instantiating program is concerned, the object remains in scope andcontinues to exist even though the object did itself in. Subsequentdereferencing of the pointer can and usually does lead to disaster. I thinkthat the language rules should disallow the idiom, but that's another matter.
In More Effective C++ (Addison-Wesley, 1996), Scott Meyers devotesone of his items to "delete this," implying that there arevalid applications for the idiom and advancing contrived code kludges to makeit seem to work better. A programmer who has read this otherwise very good bookmight think that the practice is acceptable. Experience leads me to disagree.
Q: What is a default constructor?
A: A constructor that has no arguments.
If you don't code one, the compiler provides one if there are no otherconstructors. If you are going to instantiate an array of objects of the class,the class must have a default constructor.
Q: What is a conversion constructor?
A: A constructor that accepts one argument of a different type.
The compiler uses this idiom as one way to infer conversion rules foryour class. A constructor with more than one argument and with default argumentvalues can be interpreted by the compiler as a conversion constructor when thecompiler is looking for an object of your constructor's type and sees an objectof the type of the constructor's first argument.
Q: What is the difference between a copy constructor and anoverloaded assignment operator?
A: A copy constructor constructs a new object by using the contentof the argument object. An overloaded assignment operator assigns the contentsof an existing object to another existing object of the same class.
First, the applicant must know that a copy constructor is one that hasonly one argument of the same type as the constructor. The compiler invokes acopy constructor wherever it needs to make a copy of the object, for example topass an argument by value. If you do not provide a copy constructor, thecompiler creates a member- by-member copy constructor for you.
You can write overloaded assignment operators that take arguments ofother classes, but that behavior is usually implemented with implicitconversion constructors. If you do not provide an overloaded assignmentoperator for the class, the compiler creates a default member- by-memberassignment operator.
This discussion is a good place to get into why classes need copyconstructors and overloaded assignment operators. If the applicant discussesthese with respect to data member pointers that point to dynamically allocatedresources, the applicant probably has a good grasp of the problem.
Q: When should you use multiple inheritance?
A: There are three acceptable answers: "Never,""Rarely," and "When the problem domain cannot be accuratelymodeled any other way."
There are some famous C++ pundits and luminaries who disagree with thatthird answer, but I will accept it.
Let's digress to consider this issue lest your interview turn into areligious debate. Consider an Asset class, Building class, Vehicleclass, and CompanyCar class. All company cars are vehicles. Some companycars are assets because the organizations own them. Others might be leased. Notall assets are vehicles. Money accounts are assets. Real estate holdings areassets. Some real estate holdings are buildings. Not all buildings are assets.Ad infinitum. When you diagram these relationships, it becomes apparent thatmultiple inheritance is a likely and intuitive way to model this common problemdomain. The applicant should understand, however, that multiple inheritance,like a chainsaw, is a useful tool that has its perils, needs respect, and isbest avoided except when nothing else will do.
Q: What is a virtual destructor?
A: The simple answer is that a virtual destructor is one that isdeclared with the virtual attribute.
The behavior of a virtual destructor is what is important. If you destroyan object through a pointer or reference to a base class, and the base-classdestructor is not virtual, the derived-class destructors are not executed, andthe destruction might not be complete.
Q: Explain the ISA and HASA class relationships. How would youimplement each in a class design?
A: A specialized class "is" a specialization of anotherclass and, therefore, has the ISA relationship with the other class. An EmployeeISA Person. This relationship is best implemented with inheritance.Employee is derived from Person. A class may have an instance of anotherclass. For example, an employee "has" a salary, therefore the Employeeclass has the HASA relationship with the Salary class. This relationshipis best implemented by embedding an object of the Salary class in the Employeeclass.
The answer to this question reveals whether the applicant has anunderstanding of the fundamentals of object- oriented design, which isimportant to reliable class design.
There are other relationships. The USESA relationship is when one classuses the services of another. The Employee class uses an object (cout)of the ostream class to display the employee's name on the screen, forexample. But if the applicant gets ISA and HASA right, you don't need to go anyfurther.
Q: When is a template a better solution than a base class?
A: When you are designing a generic class to contain or otherwisemanage objects of other types, when the format and behavior of those othertypes are unimportant to their containment or management, and particularly whenthose other types are unknown (thus, the genericity) to the designer of thecontainer or manager class.
Prior to templates, you had to use inheritance; your design might includea generic List container class and an application-specific Employeeclass. To put employees in a list, a ListedEmployee class is multiplyderived (contrived) from the Employee and List classes. Thesesolutions were unwieldy and error-prone. Templates solved that problem.
Questionsfor ANSI-Knowledgeable Applicants
There are six questions for those who profess knowledge of the progressof the ANSI committee. If you claim to have that much interest in the language,you should know the answers to all these questions.
Q: What is a mutable member?
A: One that can be modified by the class even when the object ofthe class or the member function doing the modification is const.
Understanding this requirement implies an understanding of C++ const,which many programmers do not have. I have seen large class designs that do notemploy the const qualifier anywhere. Some of those designs are my ownearly C++ efforts. One author suggests that some programmers find constto be such a bother that it is easier to ignore const than to try to useit meaningfully. No wonder many programmers don't understand the power andimplications of const. Someone who claims to have enough interest in thelanguage and its evolution to keep pace with the ANSI deliberations should notbe ignorant of const, however.
Q: What is an explicit constructor?
A: A conversion constructor declared with the explicit keyword.The compiler does not use an explicit constructor to implement animplied conversion of types. It's purpose is reserved explicitly forconstruction.
Q: What is the Standard Template Library?
A: A library of container templates approved by the ANSI committeefor inclusion in the standard C++ specification.
A programmer who then launches into a discussion of the genericprogramming model, iterators, allocators, algorithms, and such, has a higher thanaverage understanding of the new technology that STL brings to C++ programming.
Q: Describe run-time type identification.
A: The ability to determine at run time the type of an object byusing the typeid operator or the dynamic_cast operator.
Q: What problem does the namespace feature solve?
A: Multiple providers of libraries might use common globalidentifiers causing a name collision when an application tries to link with twoor more such libraries. The namespace feature surrounds a library's externaldeclarations with a unique namespace that eliminates the potential for thosecollisions.
This solution assumes that two library vendors don't use the samenamespace identifier, of course.
Q: Are there any new intrinsic (built-in) data types?
A: Yes. The ANSI committee added the bool intrinsic typeand its true and false value keywords.
Other apparent new types (string, complex, and so on) are implemented asclasses in the Standard C++ Library rather than as intrinsic types.
Post a Comment