May God strike down pointers

This is a discussion on May God strike down pointers within the C++ Programming forums, part of the General Programming Boards category; Hey all,
I have a problem with pointers, one which I am completely unable to comprehend. But first, here's part ...

/* This class will wrap around the position of an object if necessary
*/#ifndef CLASS_POS_REGULATOR_H#define CLASS_POS_REGULATOR_H#include "ClassStar.h"#include "ClassVector.h"#include "ClassValues.h"struct ClPosRegulator {
ClPosRegulator(ClStar& Star);
};
#endif

I'm attempting to make a simulation of star movement. It works fine, I've long since compiled it. I've been adding and tweaking ever since, and I wanted to add a class (ClPosRegulator) that would wrap the position of the star should it go off the screen. I have a class ClStar which is set up to work as a linked list (as in I have a linked list of ClStars), where m_STARS points to the first node. So what I do in the code above is loop through the "stars", calculate the displacement due to gravity using the function ClGravCalc (already been in use for some time, no problems there) and then attempt to wrap around the position of the stars using ClPosRegulator. Unfortunately, if I try to compile the above code without the cout's, it gives me a warining "unused variable curStar" on the line where I call ClPosRegulator (which is evidently nonsense as I use it before) and the "stars" don't wrap around. If I compile with the cout's, it gives me

error: 'struct ClPosRegulator' has no member named 'getPosition'
error: 'struct ClPosRegulator' has no member named 'getPosition'

If I comment out the problematic cout's (the ones containing calls to getPosition()), it compiles fine, and the remaining cout outputs only zeros. If I place the cout's before the call to ClPosRegulator, it compiles fine and they output the expected values (two values representing XY coordinates, and an address in hexadecimal), so the problem has to be somewhere in ClPosRegulator.

I know I didn't explain the logic behind 90% of the code, because I'm hoping that the error is something one of you can spot without knowing what the purpose of the code is. If you need any additional info, feel compelled to ask for it in a reply.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Well it seem very OOP to me. You need something done, and to get that something done, you have to build something else. So you build the something else, run the original something through it, and then since you're finished, destroy the something else. That might be a little confusing, so here's a pretty stupid example: I need a photo with a sand castle in it. So I build the castle, take the picture, and then, since I don't need the castle anymore, destroy the castle. Personal preference comes in because it also looks stylish in my opinion.

But you have a point with the syntactical difficulties (in my previous post I didn't know this was the cause), and I'm thinking of reimplementing the whole thing using the parenthesis operator, making an instance, and then just using that. Anyhow, thanks for the feedback everyone, you've been a great help. I'll give a shout if anything goes wrong.

If the function object doesn't need any state, and you are not going to use it as a predicate (failing to use standard C++ libraries - e.g std::list or any other container instead of reinventing the linked list - is another issue with the code), why would having an object be important.

As I said, that part is preference; I just prefer not to have functions declared basically in the middle of nowhere. I always prefer to have an object containing the function I need, even if that means declaring a completely new object.

And I never needed to use the STL libraries, since I've never done anything that would need all the stuff they offer, plus I like to do everything on my own. It's a style of learning and practicing I've developed; otherwise, I could have easily downloaded half the classes I use off the internet, and it would probably be more efficient. But as I still consider myself in the process of learning (this is my first larger program in C++) I think it's better if I do everything myself for now. Anyone can learn to use what someone else has made. I like to make the stuff as well. Also, using classes someone else made takes a great deal of fun out of the project, and that is the main reason I'm doing this at all.

But as I still consider myself in the process of learning (this is my first larger program in C++) I think it's better if I do everything myself for now.

I disagree. If you want to know how a linked list works, by all means write one yourself. But learning the standard library of a language is as important as learning the language itself, so you should use it in non-trivial programs.

As I said, that part is preference; I just prefer not to have functions declared basically in the middle of nowhere.

You're thinking like a Java programmer. C++ is a multi-paradigm language. You're supposed to pick the best from every paradigm. And having stuff that is independent of an object being done by a free function is the right thing to do.