According to Bjarne
Stroustup, designer of the C++ language, you
handle failures in a constructor
by throwing an exception. See here for more
details, including a link to his document
on exception safety and the standard library:
http://www.arkestra.demon.co.uk/errors_cpp.html#acquire_resources_in_constructors
Here is a compound expression with an insidious error.
while ( ch = nextChar() != '\0' )
<ClassName>::<StaticMemberName>.
It is const as in: int MyFunc?
(int test) const;
const char *myPointer; is a non-constant pointer to constant data; while char *const myPointer; is a constant pointer to non-constant data.
Memory is allocated in C using malloc() and freed using free(). In C++ the new() operator is used to allocate memory to an object and the delete() operator is used to free the memory taken up by an object.
Private members are accessible only by members and friends of the class. Protected members are accessible by members and friends of the class and by members and friends of derived classes. Public members are accessible by everyone.
By using the extern "C" linkage specification around the C function declarations.
The candidate should know about mangled function names and type-safe linkages. They should explain how the extern "C" linkage specification statement turns that feature off during compilation so that the linker properly links function calls to C functions.
It will turn off "name mangling" for func so that one can link to code compiled by a C compiler.
Name mangling is the rule according to which C++ changes function names into function signatures before invoking the linker. Mangled names are used by the linker to differentiate between different functions with the same name.
function's signature is its name plus the number and types of the parameters it accepts.
The default member and base class access specifiers are different.
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 specifier and private base class inheritance.
Overloading is a method that allows defining multiple member functions with the same name but different signatures. The compiler will pick the correct function based on the signature. Overriding is a method that allows the derived class to redefine the behavior of member functions which the derived class inherits from a base class. The signatures of both base class member function and derived class member function are the same; however, the implementation and, therefore, the behavior will differ.
No. Passing by value and by reference looks identical to the caller.
Compiler will allow this, but it is a bad practice since overridden member functions will hide all of the inherited overloads from the base class. You should really override all of them.
Assignment changes the value of the object that has already been constructed. Initialization constructs a new object and gives it a value at the same time.
Both non-static const data members and reference data members cannot be assigned values; instead, you should use initialization list to initialize them.
Copy constructors are called in three cases: when a function returns an object of that class by value, when the object of that class is passed by value as an argument to a function, and, finally, when you construct an object based on another object of the same class (Circle c1=c2;).
delete and delete[]?
delete deletes one object;
delete[] deletes an array of objects.
A class that has one or more pure virtual functions.
A constructor that has no arguments or one where all the arguments have default argument values.
MyClass p; and MyClass
p();?MyClass
p; creates an
instance of class
MyClass by
calling a constructor
for MyClass. MyClass
p(); declares function
p which takes no parameters and returns an
object of class
MyClass by value.
Constructors, destructors, copy constructors, assignment operators, and address-of operators.
char *a =
NULL;
char& p = *a;?
The result is undefined. You should never do this. A reference must always refer to some object.
static_cast<RWTime>(*this)
+= 5; and static_cast<RWTime&>(*this)
+= 5;?
The following statement illustrates the usefulness of a left outer join:
SELECT Customers.CustomerID?, Customers.CompanyName?, Orders.OrderID? FROM Customers LEFT JOIN Orders ON Customers.CustomerID? = Orders.CustomerID? ORDER BY Customers.CustomerID?
The join returns all the customer records from the Customers table, and relates each customer to every order number in the Orders table. By adding the ORDER BY clause, you can easily spot those customers that haven't ordered anything. (The same statement works in the Access .mdb version of Northwind.)