Skip to main content
gamedev.net
🔒 Locked

STL Compilation error?

Started by mrmrcoleman Mar 9, 2004 at 2:57 PM 5 replies 400+ views
Original Post
mrmrcoleman
mrmrcoleman
I have followed one of the STL tutorials from GameTutorials.com but I get an error straight away. To test the header I simply included it, and then declared a list of ints:
#include <list>

list<int> TestList;

But when I compile I get the following error: error C2143: syntax error : missing '';'' before ''<'' error C2501: ''list'' : missing storage-class or type specifiers error C2143: syntax error : missing '';'' before ''<'' Has anybody come across this before? I may well be doing something very silly and not realising it. Thank in advance. Mark Coleman
mrmrcoleman
mrmrcoleman
Thank you, that fixed that!

But now I have another problem ;(

In my program I have a Base class say X, and two derived classes

class Y : public X

and

class Z : public X

The idea was that I could have a list of objects which could be Y's or Z's but which could be held in a list of X's. Are Y's and Z's not also X's?

i.e. Couldnt I do the following?


list <X> BigList;
Y* NewObject = new NewObject(...);
BigList.push_front(NewObject);


The compiler is now moaning about the lack of a copy constructor in the base class even though it is present. Have a made a large mistake here?

[edited by - mrmrcoleman on March 9, 2004 4:16:39 PM]
Hazem_vb
Hazem_vb

list <X*> BigList;
Y* NewObject = new NewObject(...);
BigList.push_front(NewObject);


This will solve your problem ...

[edited by - Hazem_vb on March 9, 2004 4:47:50 PM]
Come to visit Egypt (the Land of Civilization)
mrmrcoleman
mrmrcoleman
Thank you very much for your help..

You guys are fast!

Thanks again.

Mark Coleman
risingdragon3
risingdragon3
Of course since you are using pointers, you have to delete them before removing them from the list....or use boost::shared_ptr or similar

http://www.bost.org

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.