Ok I''m all ready to leave
Sorry for the rushed messages, but I''ll elaborate a bit on what I was saying about using const whenever you could.
The purpose of const is, of course, to make a value constant so that it can''t be changed
Thus, the compiler cannot legally pass a const pointer to a function that takes a non-const pointer, because that function would be able to change what the pointer changed to.
So let''s say you wrote a function like this:
void Print(char *str); // prints out the string ''str''
and you went to call it like this:
Print("Hello, world!");
seems simple enough..
nope.. error..
"Hello, world!" is a char const *; all string literals are.
Thus, you must (and should) declare the function like this:
void Print(char const *str); // works fine now
I also said something about it being bad style to use a reference argument to allow a function to change a value.
take this function:
void nochange(int x) // uses x but doesnt change it
{
x = 5; // only changes local copy!
}
void change(int *x) // changes x
{
*x = 5; // changes what it was called with
}
later on...
int y = 7;
now you want to change y..
to get a pointer to y, you would use the address of operator..
like this:
change(&y);
it is obvious from looking at it, that y is possibly (probably) being changed by the function.
compare to:
nochange(y);
since y is being passed by value, it is impossible for the function to change it, since it could only change its local copy. this too should be obvious from looking at the call. but it''s not
enter the reference argument
void dumbchange(int &x) // no!
{
x = 5; // changes what it was called with!
}
int y = 7;
dumbchange(y);
this is perfectly legal, but very bad style.
it looks exactly like it was passed by value!
you dont need to use * in front of x = 5;
and you dont need the & in front of y
those are done automatically..
somebody could look at dumbchange(y) and assume that y wasnt being changed.
now as i stated earlier, it''s more efficient to pass a pointer to a large object than to pass a copy of it.
but putting all those *''s and ->''s next to everything can lead to some messy looking code at times..
this is okay:
void nochange(int const &x)
{
print(x);
}
nochange(y);
it LOOKS like a by-value call, and it''s safe to let people assume that y isn''t being changed.. because it cant be changed (int const &x is const!)
personally I prefer to use pointers and not references.. i prefer to use pointers all the time instead of pointers sometimes and references other times..
well now it is time for me to go.. out to eat
good luck with Extreme Tic Tac Toe!!
I checked out your web page
I''ve also struggled through most aspects of DirectX at one time or another (except that I haven''t done a lot of direct3d.. only some) and I''d be happy to help, if you don''t mind reading my huge answers!
What can I say, I like helping...
Have a nice night..
Adam M.
adamm@san.rr.com