Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7278443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:52:31+00:00 2026-05-28T22:52:31+00:00

Possible Duplicate: “Undefined reference to” template class constructor I’ve just started using templates, and

  • 0

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 <list>
#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<Tile> tilew;
    list<list<Tile>> 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 <class T> void ChangeSprite(SPRITE *newSprite,list<T> tilew,list<list<T>> tileh);

    // Virtual methods
    virtual list<Tile> 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<MapTile>(newSprite,mapTilew,mapTileh);
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:52:32+00:00Added an answer on May 28, 2026 at 10:52 pm

    It can as long as Map inherits from Grid otherwise, you would have to make ChangeSprite static, or give it a Map object to act on. Here’s a valid example of a child calling the parents templated function.

    struct Grid {
      template <class T> void ChangeSprite(/*params here*/) {
        // code here
      }
    };
    
    struct Map : public Grid {
        void Brush() {
            // bool being a placeholder for MapTile
            Grid::ChangeSprite<bool>(/*params here*/) {
                // code here
            }
        }
    };
    

    Your problem probably lies in the different files you’re using, for instance templated functions should be defined in the header file, in or below your class definition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: g++ undefined reference to typeinfo Undefined symbols “vtable for …” and “typeinfo
Possible Duplicate: sem_open() error: “undefined reference to sem_open()” on linux (Ubuntu 10.10) Having issues
Possible Duplicate: How to solve “call to undefined function domxml_new_doc()…” I'm using php5, when
Possible Duplicates: Templated function being reported as “undefined reference” during compilation Why can templates
Possible Duplicate: “using” keyword in java I'm transitioning from C# to java, so please
Possible Duplicate: Why is this function returning “undefined”? Let's assume I have the following
Possible Duplicate: Is “double hashing” a password less secure than just hashing it once?
Possible Duplicate: CSS Font Sizing - Using “/” What does it mean when there
Possible Duplicate: PHP: “Notice: Undefined variable” and “Notice: Undefined index” All of a sudden
Possible Duplicate: C# @“” how do i insert a tab? I'm trying to just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.