   templates and vectors
  I'm doing a function that is a member function of a class which looks like this:virtual void show(Player *player, vector<C> &enemyType, int element);the vector that is supposed to be many different classes, it should be able to send in many different classes. This is when I though templates could come in handy. The problem is that I can't get it to work. Am I supposed to add the template code right above the function in the class?Right now it looks something like this:class Enemy {  public:    Enemy();   template <typename C>    virtual void show(Player *player, vector<C> &enemyType, int element);    ....    ....What is wrong?   
  Member function templates can't be virtual.   ;  I removed virtual and it still showed the same errors.main.cpp `C' was not declared in this scope main.cpp template argument 1 is invalidmain.cpp template argument 2 is invalidmain.cpp ISO C++ forbids declaration of `enemyType' with no typemain.cpp prototype for `void Enemy::show(Player*, int&, int)' does not match any in class `Enemy' main.cpp template<class C> void Enemy::show(Player*, std::vector<C, std::allocator<_CharT> >&, int) main.cpp In member function `void Enemy::show(Player*, int&, int)': main.cpp `begin' has not been declared main.cpp request for member of non-aggregate type before '(' token main.cpp `enemyType' cannot be used as a function   ;  You need to show us the parts of your code these errors refer to.   ;  Ok, here is the enemy show function code which is the function that uses the vector.void Enemy::show(Player *player, vector<C> &enemyType, int element) {    if (!focus) {   move();    } else {   // if the enemy has seen the player if (px <= x)  x-=xVel;   else if (px >= x)  x+=xVel;if (py+17 >= y)  y+=yVel;   else if (py+17 <= y)  y-=yVel;}   // if the player hits the enemy    if (player->EnemyHit(x, y, enemyBox[frame].w, enemyBox[frame].h)==true) {   hp-=player->getDamage();    }   // if the player has been seen    if ((px-90 <= x + enemyBox[frame].w && px+102 >= x) && (py-90 <= y + enemyBox[frame].h && py+132 >= y)) {   focus=true;  }   // if the player is hit by the enemy    if ((px <= x + enemyBox[frame].w && px+22 >= x) && (py <= y + enemyBox[frame].h && py+42 >= y)) {   if (player->getDelay()==0) {  player->EnemyCollision(damage);  player->SetDelay(4000);   }    }   // frame/animation code    if (frame>3)   frame=0;    else   frame++;   BlitSurface(x-camera.x, y-camera.y, enemies, &enemyBox[frame]);   if (hp<=0) enemyType(enemyType.begin() + element);}The line which causes problem is: vector<C> &enemyTypeThis is an example of when I call the function in the main loop:blobs[0].show(&player, blobs, 0);blobs is the vector in the main function, that contains class instances of the inherited class Blob (inherited from Enemy).That's all I guess, right now the classes looks like this:class Enemy {  public:    Enemy();   template <typename C>    void show(Player *player, vector<C> &enemyType, int element);    virtual void move();    virtual void showhp();  protected:    int x,y;    int xVel, yVel;   bool focus;   // attributes    int experience;    int damage;    int hp;   int frame;   string direction;   // variables used for the walking process    int walkDirection;    int walkRange;    int counter;   SDL_Surface *enemies;    SDL_Rect enemyBox[3];};class Blob : public Enemy {   public:    Blob(int xPos, int yPos, string dir, int range);};By the way, all the errors refers to these lines:279: void show(Player *player, vector<C> &enemyType, int element);1705: void Enemy::show(Player *player, vector<C> &enemyType, int element) {1747: if (hp<=0) enemyType(enemyType.begin() + element);;Quote:Original post by passwordOk, here is the enemy show function code which is the function that uses the vector.*** Source Snippet Removed ***The line which causes problem is: vector<C> &enemyTypeYou forgot to repeat template <typename C>, like you had in the declaration.Quote:if (hp<=0) enemyType(enemyType.begin() + element);If enemyType is a vector, you cannot do enemyType(stuff);;  Thanks, it works now when I added another template above the function. The last part "enemyType(enemyType.begin() + element);" was supposed to be "enemyType.erase(enemyType.begin() + element);", that's why it was like that. I forgot the erase : )   