->?

Started by
12 comments, last by colinisinhere 20 years, 7 months ago
And that ladies and gentlemen is why cowsarenotevil is a copy-and-paste programmer.

^_^ j/p

James Simmons
MindEngine Development
http://medev.sourceforge.net

[edited by - neurokaotix on September 21, 2003 6:47:19 PM]
Advertisement
Yes, just remember:

MyClass Alpha;
MyClass* Beta = Α

Alpha.Function();
Beta->Function();

Do the same thing.

If you use a pointer (*) in the variable definition, you use an '->' (or (*Beta).Function()). Otherwise you use a '.'.

And if you want a convoluted explanation:
Alpha is an object. You use '.' to access functions of objects.
Beta is an address of that object. You use '->' to access functions of the object at that address.

Alpha is a box sitting in a warehouse. When you are standing next to the box, you use '.' to open it. Beta, however, is a slip of paper telling you where the box is in the warehouse. You use '->' to go to the box and open it. If you want to you can do (*Beta) to go to the box, then use '.' to open it.

I recommend reading up on C++:

C++ Interactive Course
By: Robert Lafore
ISBN 1571690638
http://www.amazon.com/exec/obidos/ASIN/1571690638/qid%3D1061975799/sr%3D11-1/ref%3Dsr%5F11%5F1/002-5897527-1676844
(and since Amazon isn't selling it: http://freebooks.by.ru/view/CppInteractiveCourse/ewtoc.html (I wouldn't link to freebooks otherwise. Note that on freebooks there seems to be some typos.))

It's a great book, and explains your question in great detail, and teaches you all about fundamental C++. Nothing about Windows, DirectX, OpenGL, Visual C++, Borland C++, or anything else, just the fundamentals of ANSI C++ and does a great job of that.

Edit Reason: HTML can be evil when it wants to be.

[edited by - Erzengeldeslichtes on September 21, 2003 8:09:33 PM]
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
quote:Original post by colinisinhere
I was reading the Quake 3 source the other day, and I see a lot of re->wc.FatGuy[T_EATME] kind of stuff. But i don''t understand this -> i see everywhere, it obviously is usful, what does it do?


Not trying to be mean or anything, but if you''re having trouble with ->, I''d keep away from the Q3 source for a while. Learn simpler things first and you''re less likely to get discouraged.

"That''s not a bug, it''s a feature!"
--me
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight
class Example {
public:
short num;

Example(short nr)
{ num = nr; }

short GetNum(void)
{ return num; }
};

Example example(2); // a normal Example variable
Example *example_ptr = new Example(3); // a new Example variable allocated somewhere in the memory (RAM) and "example_ptr" pointer recieves a reference/adress
// or...
example_ptr = &example // now "example_ptr" pointing at "example"
short exa_num, exa_ptr_num;

// get the number from "example":
exa_num = example.num;
// or...
exa_num = example.GetNum();

// get the example number via the pointer reference:
exa_ptr_num = example_ptr->num;
// or...
exa_ptr_num = example_ptr->GetNum();

ptr is short for pointer.
a pointer is a reference to the actual data.
you can access data members via a pointer.

Shouldn''t you learn C/C++ propely first before reading/studying any source codes?
Considering buying a book.

-------------------------------
Anton Karlsson
Klingis Entertainment
Games with silly humor

Aleph One (Marathon Open Source) | My Homepage

Packa bajs med winzip!

Just dreaming wont make you (more) skilled in game programming/development.

This topic is closed to new replies.

Advertisement