tag:blogger.com,1999:blog-56193058646996554812023-06-20T05:47:42.035-07:00Bob Loblaw's Law BlogPaul Burtonhttp://www.blogger.com/profile/10762822332204072319noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5619305864699655481.post-88909781321481755532008-02-15T09:49:00.000-08:002008-02-15T09:52:05.838-08:00How to implement a remove function within a stack similar to the STL implmentation:<br /><br />iterator &remove(iterator& iter)<br />{<br /> // Check if its good<br /> if (!iter.good()) return iter;<br /><br /> // Get the node<br /> Node* pDelete = iter.m_pCurr;<br /><br /> // Fix the stack's missing links<br /> if (iter.m_pPrev != NULL)<br /> iter.m_pPrev->pNext = iter.m_pCurr->pNext;<br /> else<br /> m_pTop = iter.m_pCurr->pNext;<br /><br /> if (iter.m_pPrev == NULL)<br /> iter.m_pCurr = iter.m_pPrev;<br /> else<br /> iter.m_pCurr = iter.m_pPrev->pNext;<br /><br /> // Set the current to the next node<br /> iter.m_pCurr = pDelete->pNext;<br /><br /> // Delete the data<br /> delete pDelete;<br /><br /> // One less<br /> --m_nListSize;<br /><br /> // Return the fixed iterator<br /> return iter;<br />}Paul Burtonhttp://www.blogger.com/profile/10762822332204072319noreply@blogger.com0tag:blogger.com,1999:blog-5619305864699655481.post-57086984528984966862008-02-12T20:51:00.000-08:002008-02-12T21:56:44.979-08:00C++ Interview Questions!What is operator overloading?<br />Operator overloading is writing a polymorphic function that matches one of the C++ built in operator function signatures.<br /><br />What is polymorphism?<br />Polymorphism is a concept that allows functions with different signatures to share the same name.<br /><br />Type-define a function pointer which takes an int and float as a parameter and returns a float *.<br />float*(*pfunc)(int, float)<br /><br />Declare a void pointer.<br />void* ptr<br /><br />What are templates?<br />Templates are classes in C++ that allow abstraction of data types contained within the class.<br /><br />How do you do dynamic memory allocation in C appliations?<br />malloc() allocates memory for a void pointer, free() frees the memory allocated by malloc().<br /><br />What are the advantages and disadvantages of dynamic memory allocation and static memory allocation?<br />Dynamic memory allocation can be allocated and freed during runtime while static memory allocation is allocated when the process starts and freed when the process ends.<br /><br />How do you call a C module within a C++ module?<br />extern "C" {}<br /><br />Why does C/C++ give better run-time performance than Java?<br />Java code must be ran through a java environment during runtime before it is translated into machine code while C/C++ code is compiled into assembly.<br /><br />Class A, derived B, and derived C all have the function foo(). If C is casted to A and foo() is called, what happens?<br />A's version of the foo() function will be called.<br /><br />Does C++ come with in-built threading support?<br />Visual C++ can with microsoft's process.h library, and GCC++ can through libraries like boost.<br /><br />What errors are caught at compile time?<br />Syntax, math, build, preprocessor, and run-time errors.<br /><br />What errors are caught at link time?<br />Linker errors.<br /><br />What does public and private mean in C++?<br />Public and private are access qualifiers used in structs, unions, and classes.<br /><br />What is the difference of the copy constructor and assignment operator?<br />A copy constructor is called implicitly or explicitly when a new object is being assigned to an already existing object. The assignment operator is called when an already existing object is being assigned to another already existing object.<br /><br />Why are arrays of references not possible?<br />Arrays are pointers and pointers cant point to references.<br /><br />What are callback functions?<br />Any function that can be represented as a function pointer.<br /><br />What is the volatile keyword?<br />Volatile forces the CPU to fetch the variable from system memory to cache every time it is accessed.<br /><br />Can we recurse an inline function?<br />Yes, but it is very likely that the function will not be inlined by the compiler.<br /><br />Which is the only operator in C++ that can be overloaded but not inherited?<br />The assignment operator.Paul Burtonhttp://www.blogger.com/profile/10762822332204072319noreply@blogger.com0