Hello,
I have been teaching myself C/C++ for about 6 months and am writing my first class finally.
The question I'm stumbling on at the moment is I am going through a for loop and I want to check each class object as I go through the for loop.
So sample class creation here:
class MyClass
{
private:
int vx;
int vy;
float timer;
public:
MyClass(); // default constructor
MyClass(float m_vx, float m_vy,float m_timer); // the vx,vy position and a timer
}
Okay so great created a class... now I create 2 objects
for (x = 1; x < 3; x++)
{
MyClass x = ( 100.0, 200.0, agk::Timer() + 1.0)
}
So in the instance above in my loop I have created two objects: 1, and 2 (if this is wrong please correct me)
Finally the crux of the question .. so now I want to go through another loop and check the value in the timer for each object.
I know I can do 1.timer 2.timer .. but I might actually have a hundred of these so I want to do it in a loop.
But when I do this I get an error from visual studio
for (x = 1; x < 3; x++)
{
if( (MyClass::x).timer < agk::Timer() ) doSomething() ;
}
The error is : Error: expression must have class type.
I have tried writing it other ways ... x.timer being the most obvious also does not work.
So .. any C++ coders out there have some clues for me how to approach this better?
Thank you in advance!