Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > overloading operator in a namespace

Reply
Thread Tools

overloading operator in a namespace

 
 
sinbad
Guest
Posts: n/a
 
      09-24-2010
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
 
Reply With Quote
 
 
 
 
SG
Guest
Posts: n/a
 
      09-24-2010
On 24 Sep., 10:48, sinbad wrote:
>
> 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
 
Reply With Quote
 
 
 
 
sinbad
Guest
Posts: n/a
 
      09-24-2010
On Sep 24, 2:41*pm, SG <(E-Mail Removed)> wrote:
> On 24 Sep., 10:48, sinbad wrote:
>
>
>
> > 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


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.
 
Reply With Quote
 
Öö Tiib
Guest
Posts: n/a
 
      09-24-2010
On 24 sept, 13:55, sinbad <(E-Mail Removed)> wrote:
> On Sep 24, 2:41*pm, SG <(E-Mail Removed)> wrote:
>
> > On 24 Sep., 10:48, sinbad wrote:

>
> > > 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.

>
> 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.
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      09-26-2010
sinbad <(E-Mail Removed)> wrote:
> 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:stream does for operator<< ?

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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
overloading operator->*() and operator->() gob00st@googlemail.com C++ 2 02-21-2009 04:26 AM
overloading operator->*() and operator->() gob00st@googlemail.com C++ 11 02-20-2009 08:52 PM
user defined conversion operator or operator overloading? hurcan solter C++ 3 08-29-2007 07:39 PM
Why is overloading operator. (member operator) forbidden? dascandy@gmail.com C++ 11 05-16-2007 07:54 PM
Operator overloading on "default" operator John Smith C++ 2 10-06-2004 10:22 AM



Advertisments