overloading operator in a namespace

Discussion in 'C++' started by sinbad, Sep 24, 2010.

  1. sinbad

    sinbad Guest

    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
    sinbad, Sep 24, 2010
    #1
    1. Advertising

  2. sinbad

    SG Guest

    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
    SG, Sep 24, 2010
    #2
    1. Advertising

  3. sinbad

    sinbad Guest

    On Sep 24, 2:41 pm, SG <> 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.
    sinbad, Sep 24, 2010
    #3
  4. sinbad

    Öö Tiib Guest

    On 24 sept, 13:55, sinbad <> wrote:
    > On Sep 24, 2:41 pm, SG <> 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.
    Öö Tiib, Sep 24, 2010
    #4
  5. 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.


    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.
    Juha Nieminen, Sep 26, 2010
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Smith
    Replies:
    2
    Views:
    417
    Ivan Vecerina
    Oct 6, 2004
  2. Replies:
    11
    Views:
    727
    James Kanze
    May 16, 2007
  3. hurcan solter
    Replies:
    3
    Views:
    725
    Cholo Lennon
    Aug 29, 2007
  4. Replies:
    11
    Views:
    558
  5. Replies:
    2
    Views:
    311
Loading...

Share This Page