Skip to main content
gamedev.net
🔒 Locked

using template for object pointers.

Started by GekkoCube Mar 19, 2003 at 10:31 AM 5 replies 150+ views
Original Post
GekkoCube
GekkoCube
if i have a template class, defined basically like this:
  
// please just assume everything is perfect and correct.

template< class T >
class List {
....
};
  
and lets say that I want to use this class List to hold an "array" of Object''s i tried this, it didnt work
  
List< Object* > list;
  
SabreMan
SabreMan
quote:
Original post by GekkoCube
i tried this, it didnt work

That is not a problem description!
JuNC
JuNC
quote:

// please just assume everything is perfect and correct.



Considering that something isn''t working, this isn''t a very safe assumption.
CWizard
CWizard
quote:
Original post by SabreMan
That is not a problem description!
Agreed. However, I may be able to elaborate on it.

I remember having a similar issue a while back, when trying to use a std::list<T> in a class T. The compiler complained about something (sorry, I cannot recall, and no time to test it now). I got around it by using std::list<T *> instead. And here I realize that my problem wasn''t the same as OP''s one They may, however, be related, why I post this anyway to get an excuse to bookmark it.


SabreMan
SabreMan
quote:
Original post by CWizard
Agreed. However, I may be able to elaborate on it.

Feel free to waste your time speculating on what the OP''s problem might or might not be. I''d rather not.
GekkoCube
GekkoCube
My apologies everyone.
I was quite sleepy last night but knew i had to post this in one form or another before i could attempt to even sleep.

But, thanks for the direction(s)....CWizard.
But doing what you suggested would make my template class less flexible.

Perhaps I should simply declare my use for the template class as
:


  
List< Object > list;
// instead of List< Object* > list;

Topic Locked

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

Sign in to reply to this topic.