overloading operator in a namespace

S

sinbad

hi,

is it possible to overload an operator in
a given namespace and make it available for all
the classes that are defined in that namespace.

thanks
 
S

SG

is it possible to overload an operator in
a given namespace and make it available for all
the classes that are defined in that namespace.

What do you mean by "make it available" ?
Please be more specific and/or provide an example.

Cheers!
SG
 
S

sinbad

What do you mean by "make it available" ?
Please be more specific and/or provide an example.

Cheers!
SG

i mean all the class objects in that namespace
should call the overloaded new operator for object
creation. i am new to cpp, sorry for the confusion.
basically my requirement is this. i have complex set
of classes which might be inherited, derived in different
ways. i want to do some special operations, like logging
a message for example, every time an object is created or
deleted. i want to achieve this seamlessly with minimal
changes without affecting the existing behavior of new
and delete operators.
 
Ö

Öö Tiib

i mean all the class objects in that namespace
should call the overloaded new operator for object
creation. i am new to cpp, sorry for the confusion.
basically my requirement is this. i have complex set
of classes which might be inherited, derived in different
ways. i want to do some special operations, like logging
a message for example, every time an object is created or
deleted. i want to achieve this seamlessly with minimal
changes without affecting the existing behavior of new
and delete operators.

Log from constructors and destructors of particular classes if you
want to log when object is created or destroyed. At some places
temporary objects are created (for example when passing parameters by
value) sometimes compiler may optimize it out (for example when
returning by value) and operators new and delete are not used on such
cases. Also if you are new to C++ then avoid writing debuggers, stack
tracers, deadlock detectors and memory management as first things. You
will certainly fail.
 
J

Juha Nieminen

sinbad said:
is it possible to overload an operator in
a given namespace and make it available for all
the classes that are defined in that namespace.

Isn't that what, for example, std::eek:stream does for operator<< ?

If that's not what you mean, you should explain yourself more clearly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top