1. I would like to know the difference between CMyVariable&( CString, int,
etc.. ) and CMyVariable*?
2. And for class:
What is the difference between CMyClass& and CMyClass*?
Thank you.
The main difference is that you need to use pointer syntax with the second
version (var->member).
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Landon" <Lan...@discussions.microsoft.com> wrote in message
news:FD16C2DD-3A2A-407E...@microsoft.com...
And also what is the difference with CMyClass only without anything?
Thank you.
& is the reference operator
http://msdn.microsoft.com/en-us/library/w7049scy(VS.71).aspx
* indicates a pointer
http://msdn.microsoft.com/en-us/library/89e4h321.aspx
These concepts are fundamental to C++ - I would really recommend studying
them until you know exactly what's going on and how to use them :)
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
I prefer the & because I don't have to use the silly -> everywhere (a poor language design
issue caused by a poor language design in 1975 that continues to be a perpetual annoyance)
joe
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Joseph M. Newcomer" <newc...@flounder.com> wrote in message
news:t8haf4le8hubgbo33...@4ax.com...
> And also what is the difference with CMyClass only without anything?
This is completely different. This syntax actually creates a new instance of
the specified type, while * and & reference an existing instance.
This is pretty fundamental C++. If this type of stuff is unclear, I'm not
sure you're ready to take on a large project. Rather, you should be working
your way through some books and creating small test programs.
>I don't disagree, however, I've had clients who prefer pointer syntax just
>because it makes it apparent from the call that a pointer is being passed
>and, therefore, the object coult be modified. (Not as much an issue with
>CEdit.)
Regarding the "call-site clue" and still more on when to use a pointer vs.
a reference, you might want to refer them to this message:
http://groups.google.com/group/microsoft.public.vc.mfc/msg/d9fc9e8697f860d6?hl=en
--
Doug Harrison
Visual C++ MVP
On Tue, 14 Oct 2008 23:38:22 -0600, "Jonathan Wood" <jw...@softcircuits.com> wrote:
>I don't disagree, however, I've had clients who prefer pointer syntax just
>because it makes it apparent from the call that a pointer is being passed
>and, therefore, the object coult be modified. (Not as much an issue with
>CEdit.)
> If it is intended to be modified, it is a Whatever &, and if it is not to
> be modified, it
> is a const Whatever &. So there is no need to use silly things like
> "pointer objects can
> be modified", after all, it could be a const Whatever *, so the & at the
> call site serves
> no useful purpose other than catering to the habits of 1975 PDP-11
> programmers.
The client who felt this way was not stupid, or "silly." Although I don't
apply the same rules to my own code, I can see the benefit of it.
In the practical world, I've seen cases where it added clarity to what was
happening. I don't need any more theory than that.