Overloading ++ and –

Overloading the increment (and decrement) operator creates a slight problem: there are two version of each operator,
as they may be used as postfix operator (e.g., x++) or as prefix operator (e.g., ++x).
Suppose we define a class iterator whose members can be used to visit the elements of an array. The iterator object
will return a pointer [...]

Continue Reading...

Posted in Operator Overloading, Tutorials

The explicit keyword

Assume we have a class that’s doing all kinds of interesting stuff. Its public members could be, e.g.:

class Convertor
{
public:
Convertor();
Convertor(char const *str);
Convertor(Convertor const &other);
~Convertor();
operator char const*();
void anyOtherMemberFunction();
};

Objects of the class Convertor may be constructed using a default constructor and using a char const *. [...]

Continue Reading...

Posted in Tutorials, Types, Declarations & Expressions

Overloading operator new(size_t)

If the operator new is overloaded, it must have a void * return type, and at least an argument of type size_t. The size_t
type is defined in stddef.h, which must therefore be included when the operator new is overloaded.
It is also possible to define multiple versions of the operator new, as long as each version [...]

Continue Reading...

Posted in Operator Overloading, Tutorials

Assess Your C Skills

This Quiz contains 20 questions, if you feel you are having strong C skills then it is a must quiz to assert your skills, please leave your feedback.

#include < setjmp.h >
static jmp_buf buf;

main()
{
volatile int b;
b =3;

if(setjmp(buf)!=0)
{
printf(”%d “, b);
exit(0);
[...]

Continue Reading...

Posted in Quizzes

Overloading operator delete(void *)

The delete operator may be overloaded too. The operator delete must have a void * argument, and an optional second
argument of type size_t, which is the size in bytes of objects of the class for which the operator delete is overloaded.
The returntype of the overloaded operator delete is void.
Therefore, in a class the operator delete [...]

Continue Reading...

Posted in Operator Overloading, Tutorials