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 8542799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:09:09+00:00 2026-06-11T12:09:09+00:00

I have the following method declared in the public area of a class like

  • 0

I have the following method declared in the public area of a class like that:

In the header file:

class EntityManager
{
    public:
        ...
        template <typename ComponentType>
        bool addComponentToEntity(const Entity in_Entity, const shared_ptr<ComponentType> in_ComponentInstance);
        ...
}

In the source file:

template <typename ComponentType>
bool EntityManager::addComponentToEntity(const Entity in_Entity, const shared_ptr<ComponentType> in_ComponentInstance)
{
    ...
}

Then I try to use it like this:

Entity l_Entity = 1;
shared_ptr<TestComponent> l_TestComponent(new TestComponent());
EntityManager* l_EntityManager = new EntityManager();

l_EntityManager->addComponentToEntity<TestComponent>(l_Entity, l_TestComponent);

This results in the compiler complaining:

undefined reference to `bool EntityManager::addComponentToEntity<TestComponent>(unsigned long, boost::shared_ptr<TestComponent>)'|

I am aware that this is probably because I am not very experienced in C++ programming, but I can’t see a reason why the function is undefined. I ommitted some other code that calls other functions of the EntityManager class and that works perfectly well.

I also tried rewriting the function with regular pointers, references and even passes by value with the same result.

  • 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-06-11T12:09:10+00:00Added an answer on June 11, 2026 at 12:09 pm

    Template methods/functions must be defined in the header itself (unless the method’s class itself is defined in a source file). This is also the case for all methods of a template class (even if the methods themselves aren’t template methods).

    Most people don’t even bother defining them below the class definition, they just define them inline inside the class:

    class EntityManager 
    { 
        public: 
            ... 
            template <typename ComponentType> 
            bool addComponentToEntity(const Entity in_Entity, const shared_ptr<ComponentType> in_ComponentInstance)
            {
                ...
            }
            ... 
    

    }

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

Sidebar

Related Questions

I have the following template method declared in my interface: class IObjectFactory { public:
I have following class with one static method: public class Helper { public static
I have declared a static method in class category public static function getPrefixFromSubCategoyId($subCategoryId) {
I have the following method with no modifier declared exactly in my Column class.
In header file, I declared the following as a public member variable: vector< vector<unsigned
I have declared the following extension method: public static T FindAncestor<T>(DependencyObject obj) where T
I have following method in wcf webenabled service Public Person AddPerson(Person p); As of
I have the following method, which takes in the name of a file as
I have the following method that returns void and I need to use it
I have the following method: public string Phase(string phase) { return Phase 1; }

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.