470,849 Members | 1,142 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

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

Feb 24 '06 #1
1 2477

ja***********@gmail.com wrote:
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


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;
}

Feb 24 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Morten V Pedersen | last post: by
1 post views Thread by Dom Gilligan | last post: by
31 posts views Thread by vp | last post: by
204 posts views Thread by Alexei A. Frounze | last post: by
33 posts views Thread by Ney André de Mello Zunino | last post: by
11 posts views Thread by Christopher Key | last post: by
20 posts views Thread by MikeC | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.