473,372 Members | 925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

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 2608

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Morten V Pedersen | last post by:
Hi all, I'm using the following code, but there's a problem somewhere. // Typedef af 8 arrays af 7 pointere til ints #include <iostream> using namespace std; int main()
1
by: Dom Gilligan | last post by:
What exactly can you assign to a set iterator, by assignment or initialisation? (is this covered in Josuttis? I can't find it). Some (limited) digging around in the Gnu code shows no operator=,...
31
by: vp | last post by:
If I have a pointer char * p, is it correct to assign NULL to this pointer by: "memset( &p, 0, sizeof(p));" instead of "p = NULL;" The reason I ask is I have an array of structure of N...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
8
by: Ben | last post by:
Hi, I am having trouble debugging a segmentation fault...here's my data structure: typedef struct CELL *pCELL; /* Pointers to cells */ struct CELL { SYMBOL symbol; pCELL prev_in_block;...
33
by: Ney André de Mello Zunino | last post by:
Hello. I have written a simple reference-counting smart pointer class template called RefCountPtr<T>. It works in conjunction with another class, ReferenceCountable, which is responsible for the...
3
by: john | last post by:
Hey, I know we use the pointer this to obtain a class object or class member data. I don't follow the reason for example this code. I'am quite confused assingment operator const B...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
11
by: Christopher Key | last post by:
Hello, Can anyone suggest why gcc (-W -Wall) complains, test.c:22: warning: passing arg 1 of `f' from incompatible pointer type when compiling the following code? Change the declation of f...
20
by: MikeC | last post by:
Folks, I've been playing with C programs for 25 years (not professionally - self-taught), and although I've used function pointers before, I've never got my head around them enough to be able to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.