i tested the following code as my teacher told me but it wont do what i want it to

vector<GameObjects*> blockers;

	blockers.push_back(new Wall(pictures,i,j));

	vector<GameObjects*>::iterator k = blockers.begin();
	for(;k != blockers.end(); k++){
		cout << typeid(**k).name() << endl;

what i want to get is "Class Wall"
but i only get Class GameObjects
or Class GameObjects *
what am i doing wrong? i should be able to get "class Wall" from using this typeid


Recommended Answers

All 4 Replies

Mother Of God....
found out the answer ...
why do i have to write the virtual destructor in order for this to work?
i have the solution but i dont understand it... thats worse...


i have the solution but i dont understand it... thats worse...

You can always post the whole code if you need additional help
or you can study it by yourself :)

well im making a game and i tried to use the following code in order to make
the characters stop whenever they encounter a blcoker ( someone that they cant walk
through it)
but i think its too much for the pc to handle... takes too long
any better idea? using sfml

for(;i != _drawable.end(); i++)
		cout<< typeid(**i).name();
		for (vector<Drawable *>::iterator j = _blockers.begin();j!=_blockers.end();j++)
			Radius1=(_sprite.GetSize().x + (**j)._sprite.GetSize().y) / 4;
			Radius2=((**j)._sprite.GetSize().x + (**j)._sprite.GetSize().y) / 4;
			xd = _sprite.GetPosition().x - (**j)._sprite.GetPosition().x;
			yd = _sprite.GetPosition().y - (**j)._sprite.GetPosition().y;

			cout<< xd<<" "<< yd<< " " << Radius1<< " " << Radius2<< " " << endl;
		if (sqrt(xd * xd + yd * yd) <= Radius1 + Radius2 )

ok i still dont get it... been fighting over this for a few hours
now it wont work...
Help Please :

gameObjects* _world[i][j];
King * k=new King(_pictures.getKingImage(),i,j);
cout<< typeid(_world[_x+newX][_y+newY]).name();

i want typeid name to be class King.
but will only show gameObjects *
i have a destructor and it still wont work weird

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.