How can I handle a constructor that fails? »
| 0 Comments |
Throw an exception. Constructors don’t have a return type, so it’s not possible to use
return codes. The best way to signal constructor failure is therefore to throw an exception.
Java Interview Questions | IT interview questions | Software Testing Interview questions | .Net Interview Questions | Job Interview Questions & Answers | Tough Interview Questions | Technology Interview Questions | Tech Interview Questions | Testing Interview Questions | SAP Interview Questions | ABAP Interview Questions | Data Warehousing Interview Questions
Category: C/C++ Interview Questions| 0 Comments |
Throw an exception. Constructors don’t have a return type, so it’s not possible to use
return codes. The best way to signal constructor failure is therefore to throw an exception.
| 0 Comments |
Const char *myPointer is a non constant pointer to constant data; while char *const
myPointer is a constant pointer to non constant data.
| 0 Comments |
The postfix version of operator++() has a dummy parameter of type int. The prefix version
does not have dummy parameter.
| 0 Comments |
A reference must always refer to some object and, therefore, must always be initialized;
pointers do not have such restrictions. A pointer can be reassigned to point to different
objects while a reference always refers to an object with which it was initialized.
| 0 Comments |
The process of encoding the parameter types with the function/method name into a unique name is called name mangling. The inverse process is called demangling.
For example Foo::bar(int, long) const is mangled as `bar__C3Fooil’.
For a constructor, the method name is left out.
That is Foo::Foo(int, long) const is mangled as `__C3Fooil’.
| 0 Comments |
Virtual functions are implemented using a table of function pointers, called the vtable.
There is one entry in the table per virtual function in the class. This table is created by
the constructor of the class. When a derived class is constructed, its base class is
constructed first which creates the vtable. If the derived class overrides any [...]
| 0 Comments |
The code has two built-in pitfalls. First, if it executes in a member function for an
extern, static, or automatic object, the program will probably crash as soon as the delete
statement executes. There is no portable way for an object to tell that it was instantiated
on the heap, so the class cannot assert that its object [...]
| 0 Comments |
The this pointer is a pointer accessible only within the member functions of a class, struct, or union type. It points to the object for which the member function is called. Static member functions do not have a this pointer. When a nonstatic member function is called for an object, the address of the object [...]