Tuesday, 18 December 2018

c++ - Is it legal to call a base class's template function in a child class?


Possible Duplicate:
“Undefined reference to” template class constructor






I've just started using templates, and I was wandering whether or not it is actually legal to call a template function in a child class. My problem is with the Template function ChangeSprite in the code below. It is being called in a child class, but this creates a linking error. If I remove the template part, and just give it one of the multiple things I plan on using it with instead it works fine, so I'm fearing that I won't be able to do this.



//base class
#pragma once

#include "Tile.h"
#include
#include "Sprite.h"
#include "WindowCreater.h"
#include "Directx.h"
#define LeftClickParameters WindowCreator *gw, Mouse* mouse
struct Grid
{

SPRITE *sprite;

int width, hieght;
int w, h;
int x, y;
Grid(int width, int hieght,SPRITE *sprites);
list tilew;
list> tileh;

//methods

void savefile();

void openfile();
virtual void MoveLeft() = 0;
virtual void MoveRight() = 0;
virtual void MoveUp() = 0;
virtual void MoveDown() = 0;
virtual void addrow() = 0;
virtual void deleterow() = 0;
virtual void addcolumb() = 0;
virtual void deletecolumb() = 0;


//template functions
template void ChangeSprite(SPRITE *newSprite,list tilew,list> tileh);

// Virtual methods
virtual list ReadTiles() = 0;
};


and this is where it is being called




 //how the function is being called
void Map::Brush(SPRITE *newSprite, POINT MousePosition)
{
Grid::ChangeSprite(newSprite,mapTilew,mapTileh);
}

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...