473,388 Members | 1,327 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,388 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 2609

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...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.