Home
151.
Why use static member functions when we can use global functions in CPP?

Static member functions are scoped to the class and it can be called only by using an object of the class.

152.
Is it common to use many pointers to functions and pointers to member functions?

No, these have their special uses, but are not common constructs. Many complex and powerful programs have neither. There might, however, be times when these offer the only solution.

153.
Why we use static data when we can use global data?

Static data is scoped to the class. In this manner, static data is available only through an object of the class, through an explicit call using the class name if they are public, or by using a static member function.

Static data is typed to the class type, however, and the restricted access and strong typing makes static data safer than global data.

154.
Can static member variables be private?

Yes because they are member variables and their access can be controlled like any other. If they are private, they can be accessed only by using member functions or, more commonly, static member functions.

155.
Why we need to generate an object? Why not just pass an error code ?

Because objects are more flexible and powerful than error codes. They can convey more information, and the constructor/destructor mechanisms can be used for the creation and removal of resources that might be required to properly handle the exceptional condition.

156.
Tell me the difference between a template and a macro?

Here the Templates are built in to the C++ language and are type-safe.But Macros are implemented by the preprocessor and are not type-safe

157.
Briefly explain the difference between an Array and a List?

The parameter to the template creates an instance of the template for each type. If we create six template instances, six different classes or functions are created. The parameters to the function change the behavior or data of the function, but only one function is created.

158.
Wich function will be called to initialize a class?

The constructor will be called to initialize a class. This special function has the same name as the class.

159.
Why shouldn't we make all the member data public?

Making member data private enables the client of the class to use the data without being dependent on how it is stored or computed. For example, if the Cat class has a method GetAge(), clients of the Catclass can ask for the Cat's age without knowing or caring if the Catstores its age in a member variable or computes its age on-the-fly. This means the programmer of the Catclass can change the design of the Catclass in the future without requiring all of the users of Catto change their programs as well.

160.
Tell me the difference between cerr and clog?

Here the cerr is not buffered. Everything written to cerris immediately written out. This is fine for errors to be written to the console screen, but might have too high a performance cost for writing logs to disk. But clog buffers its output, and thus can be more efficient, at the risk of losing part of the log if the program crashes.