C++ Part3

Explain the ISA and HASA class relationships. How would you implement each in a class design?

A specialized class “is” a specialization of another class and, therefore, has the ISA relationship with the other class.
This relationship is best implemented by embedding an object of the Salary class in the Employee class.

When is a template a better solution than a base class?

When you are designing a generic class to contain or otherwise manage objects of other types, when the format and behavior of those other types are unimportant to their containment or management, and particularly when those other types are unknown (thus, the generality) to the designer of the container or manager class.

What are the differences between a C++ struct and C++ class?

The default member and base-class access specifies are different.
This is one of the commonly misunderstood aspects of C++. Believe it or not, many programmers think that a C++ struct is just like a C struct, while a C++ class has inheritance, access specifies, member functions, overloaded operators, and so on. Actually, the C++ struct has all the features of the class. The only differences are that a struct defaults to public member access and public base-class inheritance, and a class defaults to the private access specified and private base-class inheritance.

How do you know that your class needs a virtual destructor?

If your class has at least one virtual function, you should make a destructor for this class virtual. This will allow you to delete a dynamic object through a baller to a base class object. If the destructor is non-virtual, then wrong destructor will be invoked during deletion of the dynamic object.

What is the difference between new/delete and malloc/free?

Malloc/free do not know about constructors and destructors. New and delete create and destroy objects, while malloc and free allocate and deallocate memory.

What happens when a function throws an exception that was not specified by an exception specification for this function?

Unexpected() is called, which, by default, will eventually trigger abort().

Can you think of a situation where your program would crash without reaching the breakball, which you set at the beginning of main()?

C++ allows for dynamic initialization of global variables before main() is invoked. It is possible that initialization of global will invoke some function. If this function crashes the crash will occur before main() is entered.

What issue do auto_ptr objects address?

If you use auto_ptr objects you would not have to be concerned with heap objects not being deleted even if the exception is thrown.

Is there any problem with the following:
char *a=NULL; char& p = *a;?

The result is undefined. You should never do this. A reference must always refer to some object.

Posted in C/C++. 7 Comments »

7 Responses to “C++ Part3”

  1. Ondrej Spanel Says:

    Crazy – baller instead of pointer? balled instead of pointed? and best of all breakball instead of breakpoint?

    What clbuttic is this?

    (See http://stackoverflow.com/questions/374945 for a related discussion)

  2. Sarkar Says:

    Do fhul. Ek sath kabhi khila nhi karte
    Suche pyr karne wale kabhi mila nhi karte
    I am sarkar

  3. Sarkar Says:

    सिगरेट 🚭 वाले से उधार 💵 और खुबसूरत लड़कियों 💁 से प्यार 😍,जितना भी रोको 😉 हो ही जाता है !!
    Sarkar

  4. Sarkar Says:

    हर आदमी अपनी Zindagi में Hero 🏃 Hai, Bas कुछ लोगों ki 💥 फिल्में 🎥 रिलीज़ नहीं Hoti.
    Sarkar

  5. Sarkar Says:

    Lagta hai ‎Maa Baap‬ ne bachpan me khilone nahi Dilaye,Tabhi to Pagli‬ hamare dil se khel gyi.
    Sarkar


Leave a reply to Sarkar Cancel reply