Interview Questions
C++ |
class opOverload{ public: bool operator==(opOverload temp); }; bool opOverload::operator==(opOverload temp){ if(*this == temp ){ cout<<"The both are same objects\n"; return true; } else{ cout<<"The both are different\n"; return false; } } void main(){ opOverload a1, a2; a1= =a2; } |
Ans: Runtime Error: Stack Overflow |
Just like normal functions, operator functions can be called recursively. This program just illustrates that point, by calling the operator == function recursively, leading to an infinite loop. . |
#include class fig2d { int dim1; int dim2; public: fig2d() { dim1=5; dim2=6;} virtual void operator<<(ostream & rhs); }; void fig2d::operator<<(ostream &rhs) { rhs |
Ans: 5 6 |
In this program, the << operator is overloaded with ostream as argument.This enables the 'cout' to be present at the right-hand-side. Normally, 'cout'is implemented as global function, but it doesn't mean that 'cout' is not possible to be overloaded as member function.Overloading << as virtual member function becomes handy when the class in which it is overloaded is inherited, and this becomes available to be overrided. This is as opposed to global friend functions, where friend's are not inherited.. |
What is an opaque pointer? |
Ans: A pointer is said to be opaque if the definition of the type to which it points to is not included in the current translation unit. A translation unit is the result of merging an implementation file with all its headers and header files. |
What is a parameterized type? |
Ans: A template is a parameterized construct or type containing generic code that can use or manipulate any type. It is called parameterized because an actual type is a parameter of the code body. Polymorphism may be achieved through parameterized types. This type of polymorphism is called parameteric polymorphism. |
When can you tell that a memory leak will occur? |
Ans: A memory leak occurs when a program loses the ability to free a block of dynamically allocated memory. |
What is a concrete class? |
Ans: A concrete class is used to define a useful object that can be instantiated as an automatic variable on the program stack. The implementation of a concrete class is defined. The concrete class is not intended to be a base class and no attempt to minimize dependency on other classes in the implementation or behavior of the class. |
Pages
- « first
- ‹ previous
- 1
- 2
- 3
- 4