Advertisement

I need a book (or somebody's project source code) which properly explains OOP

Started by April 12, 2016 06:30 AM
22 comments, last by alh420 8 years, 8 months ago
myList()
Since myList is neither a function nor has an operator () this does not make any sense.

I took a few days break from programming and I'm back to the error hunting again.


    std::list<Thing> myList;
    myList.push_back(Thing(10, 12));
    myList.push_back(Thing(11, 13));

for (Thing& thing : myList)
      myList()->drawMe(wallGFX, screen);

error: no match for call to '(std::list<Thing>) ()'

So I think the second part there is supposed to get the pointer to the object then access its method. By the error it seems it cannot find the objects, or perhaps it cannot find the list. Both the list and its objects are declared in the main function :blink:

Take a step back and think for a bit.

What does this do?

for (Thing& thing : myList)

With that in mind, which one variable do you always expect to see used in the loop body, regardless of what the loop does?

Now you should be able to see the problem.

Advertisement

I definitely need to take a step back... I was implementing BitMaster's code into my program and somehow that part was not updated. It was meant to be:


thing.drawMe(/* function arguments here */);

That makes a million times more sense. Instead of trying to call a list as if it were a function, I'm meant to access the object's member function duh. After too many hours in front of the screen (no matter how dimmed) my eyes go blurry and I cease to make sense to myself.

Logging in from unsecured wireless, I hope no-one steals my password (October 22, 2016)

After too many hours in front of the screen (no matter how dimmed) my eyes go blurry and I cease to make sense to myself.

No worries, happens to us all :)

Sometimes all you need is to go to bed, and the problem is much clearer in the morning.

This topic is closed to new replies.

Advertisement