Post has been edited after doing some fact checking.
I have checked out some of your other posts and I can not stop myself from saying, it sounds like you are diving too deep too fast.
This is EXACTLY the mistake I am currently making. I will recommend this particular book:
Programming Principles and Practice Using C++ by Bjarne Stroustrup. If you are not a mathematician (I am not) you will get lost at points. The book does do a lot to clear up ambiguity about how code does work, should work, and even when it is worthy for your needs. Go to the library and check out a copy before you make the puchase. For the novice it can be a little intense. I still, as a dim bulbed programmer, constantly dip into it and try to divine the simplest, cleanest code I can write.
Now about pointers. In the sense of simple, trivial game programming you will find that you will not need them often at all. One thing about pointers is that they offer easier access to member functions, member objects, and a way to avoid global variables (the last can be dangerous because it can lead to pointers all over your code where you may not need them instead of structuring clean simple codeblocks). A pointer ONLY provides low level access to a specific block of memory that you want to use. Pointers are an advanced tool that has many, many uses... But not for the newly iniatited programmer.
Many new programmers often confuse pointers (
pointing) with references (
referring). If you want to use a variable without copying it (which will take up valuable RAM in large, intense programs). What follows is almost verbatum from that book that I suggested above.
What if a value that you wish to pass from one function to another is large, such as an image (often, several million bits), a large table of values (say, thousands of integers), or a long string (say, hundreds of characters)? then, copying can be costly. We should not be obsessed by cost, but doing unnecessary work can be embarrassing because it is an indication that we didn't directly express our idea of what we wanted. For example, we could write a function to print out a vector of floating-point numbers like this:
void print(vector<double> v)
{
cout << "{ ";
for (int n = ); n < v.size( ); ++n)
{
cout << v[n];
if (n != v.size( ) - 1)
cout << ", ";
}
cout << " }\n";
}
We could use this print() for vectors of all sizes. For example:
void f(int x)
{
vector<double> vdl(10); // small vector
veclor<double> vd2(1000000); // large vector
veclor<double> vd3(x); // vector of some unknown size
// . . . fill vd l , vd2, vd3 with values ..
print(vd1);
print(vd2);
print(vd3);
}
This code works, but the first call of print( ) has to copy ten doubles (probably 80 bytes), the second call has to copy a million doubles (probably 8 megabytes). and we don't know how much the third call has to copy. The question we must ask ourselves here is: "why are we copying anything at all?" We just wanted to print the vectors, not to make copies of their elements. Obviously, there has to be a way for us to pass a variable to a function without copying it. As an analogy, if you were given the task to make a list of books in a library, the librarians wouldn't ship you a copy of the library building and all its contents; they would send you lhe address of the library, so that You could go and look all the books.
So, we need a way of giving our print() function "the address" of the vector to print() rather than the copy of the vector. Such an "address" is called a
reference and is used like this:
// passes the contents of vector by reference without copying
void print(const vector<double>& v)
{
cout << "{ ";
for (int n = 0: n < v.size( ): ++n)
{
cout<< v[n];
if (n != v.size( ) - 1) cout << ", ";
}
cout << " }\n";
}
The
& means "reference" and the const is there to stop print() from modifying its argument by accident. Apart from the change to the argument declaration, all is the same as before; the only change is that instead of operating on a copy, print() now refers back to the argument through the reference. Note the phrase "refer back"; such arguments are called references because they "refer" to objects defined elsewhere. We can call this print() exactly as before:
void f(int x)
{
vector<double> vdl(10); // small vector
veclor<double> vd2(1000000); // large vector
veclor<double> vd3(x); // vector of some unknown size
// . . . fill vd l , vd2, vd3 with values ..
print(vd1);
print(vd2);
print(vd3);
}
But with much less strain on the computer, thus improving the computer's performance whenever the call to print() is made.
Pointers are convinient when you NEED to
point to the area of the memory instead of just referring to it. Pointers are an area you should explore outside of any big projects and just
refer otherwise... Atleast that is what I think... I am not so much smert...
I invite any veterens to audit my response and correct any misinformation.
I'm not suggesting we should eradicate all stupid people. I am just saying lets remove all of the warning lables and let the situation sort its self out.