Hey guys, harassing you for a simple reason: we're both pretty bored, I'm coding, and I hit a problem that google doesn't want to give its secrets for.
I'm making a game as a final project for this semester in C++, and I have a class "Actor" defined that is the root class for the "enemy", "sprite" and all other classes - essientially, it's a bitmap (i'm using Allegro) in an object with useful functions. I have a game engine which hold a list to pointers to all these objects, a list of Actors*. However, when I attempt to iterate through the list, on decleration of my iterator, g++ tells me,
"Engine.h:48: error: no match for call to '(std::list<Actor*, std::allocator<Actor*> >) (std::_List_iterator<Actor*>&)'
"
The line of code is "list<Actor*>::iterator pos = gameObjects.begin();"
So, any ideas?
Also, I am not a bbcode expert.
Name:
Anonymous2009-03-22 2:52
Also, gameObjects is declared as list<Actor*> gameObjects;, but I don't think that helps too much.
>>5
Ask your professor you faggot. /prog/ is not for CS101 help.
Name:
Anonymous2009-03-22 3:25
>>6
Sweet. Then I get to hear,
"Dat is un compiler pwoblem. Uz das Vindows cumpiler, and ju vill be fine."
When was the last time you had a competent proffesor, dick?
If I'm so retarded, the answer's obvious - the answer that's not "C++ sucks dick"; that I've picked up on.
You're problem is that your lying about the code you used. Post what it actually says.
Name:
Anonymous2009-03-22 3:35
//screen.h: definition of the game engine, which does all screen output
#pragma once
#include "Actor.h"
#include "fighter.h"
#include "bullet.h"
#include <iostream>
#include <allegro.h>
#include <cstring>
#include <loadpng.h>
#include <png.h>
#include <list>
#include <vector>
using namespace std;
class Actor; //solves a circular dependancy
void drawToBuffer(BITMAP* sprite, int x, int y)
{
draw_trans_sprite(offscreen, sprite, x, y);
}
void flip_page(void)
{
// flip to the buffer
show_video_bitmap(offscreen);
// set the buffer to the other page
offscreen = video_page[offscreen_page = 1 - offscreen_page];
}
void UpdateScreen()
{
flip_page();
clear(offscreen);
list<Actor*>::iterator pos = GameObjects.begin(); //fuck this line to HELL
while(pos != GameObjects.end())
{
pos->update();
pos++;
}
}
void AddActor(Actor* Newbie)
{
GameObjects.push_front(Newbie);
}
private:
int offscreen_page; // integer saying which is the offscreen page, 0 or 1.
BITMAP* video_page[2]; //the two pages the to draw pixels to
BITMAP* offscreen; //the current of-screen page to draw to.
list<Actor*> GameObjects;
};
>>7 When was the last time you had a competent proffesor
This semester.
If you meant when was the last time I had in incompetent professor. It was before I transferred to an ivy league university. Oddly enough- here they are all the worlds best in their field.
>>11
Please, allow me to apologize for mistaking this as a place for informal discussion. I see now thanks to your expert guidance that this board is strictly formal and all English mistakes are punishable by having respondents conmpletely ignore anything else you said.
>>12
Please allow me to forgive your ignorance. It is not often someone completely misses the irony in saying they are educated, then making a simple grammatical mistake.
Wait, you guys haven't told me yet.
Dicks.
I could become a regular /prog/go, posting meaningless memes and spouting garbage throughout your precious board.
Setting http://dis.4chan.org/read/prog as my home page in 3...2...
You also forgot the [code] tags.
If you don't tell us it's code, how are we supposed to know?
Name:
Anonymous2009-03-22 8:50
The forward reference
class Actor; //solves a circular dependancy (sic)
comes after the inclusion of Actor.h -- was this intentional?
Putting this into VC++, clearing out the header files I don't have in favour of
class Actor {
public:
void update();
};
class BITMAP;
I get
1>c:\users\######\documents\visual studio 2008\projects\dummy\cppscratch[spoiler]prog[/spoiler].cpp(44) : error C2839: invalid return type 'Actor **' for overloaded 'operator ->'
1>c:\users\######\documents\visual studio 2008\projects\dummy\cppscratch[spoiler]prog[/spoiler].cpp(44) : error C2039: 'update' : is not a member of 'std::list<_Ty>::_Iterator<_Secure_validation>'
1> with
1> [
1> _Ty=Actor *
1> ]
1> and
1> [
1> _Secure_validation=true
1> ]
referring to this line
pos->update();
The first of which indicates a problem, maybe even the same one the gay g++ message is talking about.
Name:
Anonymous2009-03-22 9:48
pos is an iterator.
dereference it.
Name:
Anonymous2009-03-22 12:05
>>22
It wasn't intentional; I have no other way that I know of including that class in that header file, and it is needed. That circular dependency was a bitch. Should it be before the inclusion? The site I got this tip from wasn't very clear. Moving it to before the inclusion doesn't do anything for the iterator problem.
As for the iterator mistakes, thank you for that, but my compiler doesn't even reach those before it says no, as it doesn't see the iterator being declared. The line where I say [code]
list<Actor*>::iterator pos = GameObjects.begin(); //fuck this line to HELL
[code]
doesn't work, so naturally I don't get the iterator errors. I can take those lines out of my code, and still get the error at the above line. :/
>>37
Goddammit fronk, the thread's over. Your solution doesn't work, because your other assertion is correct - I am a retard, and the problem was the #includes, not that line. Doing what you suggest in the (now old) code fixes a small part of a far larger error. Now stop bumping this shit, you dick.