Sign in to follow this  

Template Travesty

This topic is 2040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have some code that tries to create a linked list out of vectors and using templates for the first time I guess it's inevitable that it'll be wrong =P.

The relevance (LinkedList.h):

[CODE]
#pragma once
#include <vector>
#include "Main.h"
template <typename T>
int FindEmptyID(std::vector<T*> &vector)
{
if(list.empty())
{
return DEFAULT_ID;
}
else
{
typename std::list<T*>::iterator i = list.begin();
int previousId = (*i)->ID();
i++;
for(; i != list.end(); i++)
{
int currentId = (*i)->ID();
if(currentId - previousId > 1)
{
return previousId + 1;
}
previousId = currentId;
}
return previousId + 1;
}
}
template <typename T>
T * cLinkedList <T>::ScanListPrevious(std::vector<T*> &vector, int ID)
{
T *previous = 0;
for(typename std::list<T*>::iterator i = list.begin() ; i != list.end() ; ++i)
{
T *object = *i;
if(object->ID() == ID)
{
return previous;
}
previous = object;
}

return 0;
}
template <typename T>
T * cLinkedList <T>::ScanList(std::vector<T*> &vector, int ID)
{
for(typename std::list<T *>::iterator i = list.begin(); i != list.end(); ++i)
{
T *object = *i;
if(object->ID() == ID)
{
return object;
}
}
return 0;
}
[/CODE]

LinkedList.h gets called in (and used only in) TileContainer.h where it's used to typecast some things.

TileContainer.h:

[CODE]
#pragma once
#include "LinkedList.h"
#include "sSprite.h"

class LayerContainer
{
public:
int ID;
LayerContainer();
~LayerContainer();
private:
LayerContainer* layers;
};

class TileContainer
{
public:
sSprite background, middle, foreground; // Graphical rendering of the tile
int rowPos, colPos; // Position of the tile
int rowSpr, colSpr; // Position of the sprite from the sprite sheet to render
int ID;
int layerNum;

// Function declarations
TileContainer();
~TileContainer();
void AddTile(int row, int column, int size, int rowSpr, int colSpr);
void ChangeTileSprite(sSprite sprite, int depth, int ID);
void AddTileLayer(sSprite sprite, int row, int col);
void AddTileLayer(sSprite sprite, int ID);
private:
TileContainer* tiles;
};

typedef std::vector<LayerContainer> LayerContainer;
typedef std::vector<TileContainer> TileContainer;
[/CODE]


The errors:

[img]http://i50.tinypic.com/1hft3a.png[/img]

I'm not quite sure what's wrong with it and the errors don't really help me (perhaps if I knew more about templates), so if anyone could point me in the right direction it'd me much appreciated.

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1336708802' post='4939197']
Where is the class cLinkedList declared?
[/quote]

That's a good question =P. They were supposed to be free functions, but for some reason I made them a part of a class and then deleted the class and...this is what I get for going back to year-old code. Thanks for the help, should've realized that sooner. Fixed it =).

Share this post


Link to post
Share on other sites

This topic is 2040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this