Pointer assignment

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jasonbessette@gmail.com

    #1

    Pointer assignment

    Say I have the following line:

    Nothing *here = &doing;

    My nothing class is just this:

    class Nothing
    {
    };

    I need to explicitly provide what the compiler implicitly provides. So
    basically I need fill in my nothing class with the function that the
    above line will call and I have no clue! I have the first three lines
    in Main figured out, it's just the last two that I need help with. Here
    is what I have so far with the other things for this class


    Nothing.h =============== =========
    class Nothing
    {
    public:
    Nothing()
    {
    cout << "Executing the default constructor ========>" << endl;
    }

    Nothing(const Nothing&)
    {
    cout << "Executing the copy constructor =============== ====>" <<
    endl;
    }

    Nothing& operator=(const Nothing &rhs)
    {
    cout << "Executing the assignment operator =============== =>" <<
    endl;
    return *this;
    }
    };

    Nothing.cpp =============== =============== ===========

    #include "nothing.h"

    int main()
    {
    const Nothing ness;

    Nothing doing(ness);

    doing = ness;

    Nothing *here = &doing;
    const Nothing *anywhere = &ness;

    return 0;
    }


    -Jason

  • ferdinand.stefanus@gmail.com

    #2
    Re: Pointer assignment


    jasonbessette@g mail.com wrote:[color=blue]
    > Say I have the following line:
    >
    > Nothing *here = &doing;
    >
    > My nothing class is just this:
    >
    > class Nothing
    > {
    > };
    >
    > I need to explicitly provide what the compiler implicitly provides. So
    > basically I need fill in my nothing class with the function that the
    > above line will call and I have no clue! I have the first three lines
    > in Main figured out, it's just the last two that I need help with. Here
    > is what I have so far with the other things for this class
    >
    >
    > Nothing.h =============== =========
    > class Nothing
    > {
    > public:
    > Nothing()
    > {
    > cout << "Executing the default constructor ========>" << endl;
    > }
    >
    > Nothing(const Nothing&)
    > {
    > cout << "Executing the copy constructor =============== ====>" <<
    > endl;
    > }
    >
    > Nothing& operator=(const Nothing &rhs)
    > {
    > cout << "Executing the assignment operator =============== =>" <<
    > endl;
    > return *this;
    > }
    > };
    >
    > Nothing.cpp =============== =============== ===========
    >
    > #include "nothing.h"
    >
    > int main()
    > {
    > const Nothing ness;
    >
    > Nothing doing(ness);
    >
    > doing = ness;
    >
    > Nothing *here = &doing;
    > const Nothing *anywhere = &ness;
    >
    > return 0;
    > }
    >
    >
    > -Jason[/color]

    I'm not sure I get your intention here, but if you want the address-of
    operator (&) to behave differently, you can always overload it, e.g.:

    Nothing* operator&()
    {
    cout << "In address-of operator\n";
    return this;
    }

    Comment

    Working...