What's 'im'? Is that a member? Of what, 'q' or '*this'? If it's
(supposedly) the member of '*this', then you're trying to change the
'*this' object, right? And you just declared that object 'const' by
putting 'const' after the function declaration (before the curly
brace). So, even if the syntax were accepted (I don't think it
should be, since ~ is an unary operator, so it shouldn't have any
arguments), the compilation shouldn't let you change a const object.
Hello. Sorry about the delayed response. I did follow up a yesterday
but for some reason my post never showed up.
Yes, 'im' is a member. Well, you have pretty much clarified things a
bit for me. Yes, I did think I was dealing with a 'this' pointer. And,
apparently there is one. But, I completely ignored that this was
const function.
*What* book? I am asking so that we'd recommend people against it
since it doesn't seem to have correct C++ examples.
Stephen Prata's "C++ Primer Plus". It actually is not the book's
fault. The blame resides with my difficulty in grasping the material. C
++ is a very complicated language. I was trying to learn through
reading Deitel & Deitel's 4th edition, but six weeks and 600 pages
into that book I had to set it down. Then I turned to Prata and he is
at least giving me some handle on the language. But it still takes a
lot of work, a lot of time and a lot of practice. I also have tic++
on my harddrive and I will be reading that down the road. But over
half way through Prata. But, if you have a recommendation I'm open to
suggestions. "Accelerated C++" left me in the dust, though.
OKAY? Are you saying it will compile? How is 'Complecks' defined?
Yes, this code compiles and runs fine. Why not? It does create a new
object. Unless you mean that the expressions imply that there is
indeed a "this" pointer. I guess there does have to be a "this"
pointer.
================
class Complecks{
private:
double real;
double im;
public:
Complecks();
Complecks(double p, double q);
Complecks operator+(const Complecks& q)const;
Complecks operator-(const Complecks& q)const;
Complecks operator*(const Complecks& q)const;
Complecks operator~();
friend Complecks operator*(double x, const Complecks& q);
friend std:

stream& operator<<(std:

stream& os, const Complecks&
q);
friend std::istream& operator>>(std::istream& is, Complecks& q);
};
===========================
and then...
===========
//one of two constructors:
Complecks::Complecks(double p, double q){
real = p;
im = q;
}
//and the final way I implemented the "~" operator:
Complecks Complecks:

perator~(){
Complecks obj;
obj.real = real;
obj.im = -im;
return obj;
}
================
I don't know if this is all you want to see or not. But apparently
there is a "this" operator.
Right. Here I was wrong. Although the example program didn't use "~c"
with an assignment operator, it could have done that. Instead the "~c"
was used in an ostream, and it returned the value to the ostream.
But, I guess the only reason the overloaded operator wouldn't return a
value with the first code was that it was declared void and constant.
It's up to you of course, but the operator~ (just like the operator!
or the operator-) is NOT supposed to change the object for which it
is called. It is supposed to return a new object:
Complecks Complecks:

perator~() const {
return Complecks(real, -im); // there is a c-tor for that I hope
}
Yes, your code would also work.
or
Complecks operator~(Complecks const& q) {
return Complecks(q.real(), -q.imaginary());
}
(supposing that you have defined 'Complecks' with needed constructor
and accessors).
This wouldn't work with the code I have, but yes, I can see how that
would work with the right setup.
Thanks for your input, I think this has cleared up some of my
understanding. But, do you agree that the overloaded ~ operator
function does have a "this" pointer?