Advanced C++: Answer
Advanced C++: Answer
C++ Tutorial
5. Question 5. What Is The Memory Structure Of An Object?
Answer :
Usually C++ objects are made by concatenating member variables.
For example;
class Test
{
int i;
float j;
};
is represented by an int followed by a float.
class TestSub: public Test
{
int k;
};
The above class is represented by Test and then an int(for int k). So finally it will
be int, float and int.
In addition to this each object will have the vptr(virtual pointer) if the class has
virtual function, usually as the first element in a class.
Java Tutorial
o Question 11. What Is A Possible Replacement For C Static Function
In C++?
Answer :
Unnamed namespaces.
INFOSYS C++
1. Question 1. What Is Virtual Constructors/destructors?
Answer :
Virtual destructors: If an object (with a non-virtual destructor) is destroyed
explicitly by applying the delete operator to a base-class pointer to the object, the
base-class destructor function (matching the pointer type) is called on the object.
There is a simple solution to this problem – declare a virtual base-class
destructor. This makes all derived-class destructors virtual even though they don’t
have the same name as the base-class destructor. Now, if the object in the
hierarchy is destroyed explicitly by applying the delete operator to a base-class
pointer to a derived-class object, the destructor for the appropriate class is called.
Virtual constructor: Constructors cannot be virtual. Declaring a constructor as a
virtual function is a syntax error. Does c++ support multilevel and multiple
inheritance.
2. Question 2. Why Garbage Collection?
Answer :
Since C++ does not provide automatic garbage collection like some other
languages, smart pointers can be used for that purpose. The simplest garbage
collection scheme is reference counting or reference linking, but it is quite
possible to implement more sophisticated garbage collection schemes with
smart pointers.
Java Tutorial
17. Question 17. What Are Virtual Functions?
Answer :
A virtual function allows derived classes to replace the implementation provided
by the base class. The compiler makes sure the replacement is always called
whenever the object in question is actually of the derived class, even if the object
is accessed by a base pointer rather than a derived pointer. This allows
algorithms in the base class to be replaced in the derived class, even if users don't
know about the derived class.