Skip to main content
gamedev.net
🔒 Locked

Template problems..

Started by bzroom 3 replies 500+ views
Original Post
bzroom
bzroom
I'm writting sort of a vector class, and when I try to use the array index operator I get an error that I dont understand. Any suggestions? This line: cMaterial *mat = materials[material];
Generates this error: error C2440: 'initializing' : cannot convert from 'SmartList' to 'cMaterial *' with [ T=cMaterial ]
Here is the definition:

SmartList<cMaterial> *materials;
 

And the function definition:
T* SmartList<class T>::operator[](long index) 
{
	if (list[index])
		return list[index]->object;
	else
		GenError("Invalid Smartlist Index");
}
    
edit: stupid < >'s [edited by - honayboyz on May 12, 2004 9:30:34 PM] [edited by - honayboyz on May 12, 2004 9:31:59 PM] [edited by - honayboyz on May 12, 2004 9:33:26 PM] [edited by - honayboyz on May 12, 2004 9:34:12 PM]
SiCrane
SiCrane
Did you try derefercing the pointer before you applied operator[] to it? i.e.: cMaterial *mat = (*materials)[material];
Sneftel
Sneftel
Are you sure you mean "SmartList<cMaterial> *materials;", as opposed to "SmartList<cMaterial *> materials;"?


"Sneftel is correct, if rather vulgar." --Flarelocke
bzroom
bzroom

I think so, heres the whole class def.


template <class T>
class SmartList
{
private:
struct sEntry
{
char *name;
long dependencys;

T *object;

sEntry(char *name_, T* object_);
~sEntry();
};

sEntry **list;
long listsize;
long liststep;


public:
SmartList(long size, long step);
~SmartList();

long FindEntry(char *name);
long AddEntry(char *name, T *object);
bool RemoveEntry(char *name); //true if actualy deleted, if u care

bool RemoveEntry(long entry);
void Clear();

T* operator[](long index);
};
bzroom
bzroom

Good call SiCrane, thank you.

Topic Locked

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

Sign in to reply to this topic.