How do I initialize a pointer to a
function?
This is the way to initialize a pointer to a function
void fun(int a)
{
}
void main()
{
void (*fp)(int);
fp=fun;
fp(1);
}
How do you link a C++ program to C functions?
By using the extern "C" linkage specification around the C function
declarations.
Explain the scope resolution operator.
It permits a program to reference an identifier in the global scope that
has been hidden by another identifier with the same name in the local
scope.
What are the differences between a C++ struct and C++ class?
The default member and base-class access specifier are different.
How many ways are there to initialize an int with a constant?
Two.
There are two formats for initializers in C++ as shown in the example
that follows. The first format uses the traditional C notation. The
second format uses constructor notation.
int foo = 123;
int bar (123);
How does throwing and catching exceptions differ from using setjmp
and longjmp?
The throw operation calls the destructors for automatic objects
instantiated since entry to the try block.
What is a default constructor?
Default constructor WITH arguments class B { public: B (int m = 0) : n
(m) {} int n; }; int main(int argc, char *argv[]) { B b; return 0; }
What is a conversion constructor?
A constructor that accepts one argument of a different type.
What is the difference between a copy constructor and an overloaded
assignment operator?
A copy constructor constructs a new object by using the content of the
argument object. An overloaded assignment operator assigns the contents
of an existing object to another existing object of the same class.
When should you use multiple inheritance?
There are three acceptable answers: "Never," "Rarely," and "When the
problem domain cannot be accurately modeled any other way."
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. An Employee
ISA Person. This relationship is best implemented with inheritance.
Employee is derived from Person. A class may have an instance of another
class. For example, an employee "has" a salary, therefore the Employee
class has the HASA relationship with the Salary 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 generosity)
to the designer of the container or manager class.
What is a mutable member?
One that can be modified by the class even when the object of the class
or the member function doing the modification is const.
What is an explicit constructor?
A conversion constructor declared with the explicit keyword. The
compiler does not use an explicit constructor to implement an implied
conversion of types. It’s purpose is reserved explicitly for
construction.
Page Numbers
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17