How to determine that a specific method of a C ++ class uses templates?

I have a problem with C ++ templates. Here is an explanation of what I'm trying to do so that everyone can better understand my problem.

My structure has a base class Component, and users of my structure will get Componentto create a specific one Components, for example, TransformComponentand AudioComponent. A ComponentCompositestores a list of all the specific ones Componentcreated by a given user.

I am trying to keep the list specific Componentsthrough boost::anyand boost::any_casts.

Below are two methods in ComponentCompositeand my list boost::any.

    class ComponentComposite {

        public:
            ComponentComposite();
            template<class T> bool addComponent(T* component);
            template<class T> T* getComponent();

        private:
            QList<boost::any*>* m_components;
    }

GameObject, ComponentComposite. Component GameObject, Component. ComponentComposite.

    GameObject::GameObject() : ComponentComposite()
    {
        addComponent<Components::AudioComponent>(new Components::AudioComponent());
        addComponent<Components::TransformComponent>(new Components::TransformComponent());
        Components::TransformComponent* transform= getComponent<Components::TransformComponent>();
        Components::AudioComponent* audio= getComponent<Components::AudioComponent>();
    }

( ):

  • ...undefined reference to `bool BalaurEngine::Composites::ComponentComposite::addComponent<BalaurEngine::Components::AudioComponent>(BalaurEngine::Components::AudioComponent*)'
  • ...undefined reference to `bool BalaurEngine::Composites::ComponentComposite::addComponent<BalaurEngine::Components::TransformComponent>(BalaurEngine::Components::TransformComponent*)'
  • ...undefined reference to `BalaurEngine::Components::TransformComponent* BalaurEngine::Composites::ComponentComposite::getComponent<BalaurEngine::Components::TransformComponent>()'
  • ...undefined reference to `BalaurEngine::Components::AudioComponent* BalaurEngine::Composites::ComponentComposite::getComponent<BalaurEngine::Components::AudioComponent>()'

- , template<class T> bool addComponent(T* component); template<class T> T* getComponent();

+3
1

- . :

@Mutmansky, , ++ . , , , . , / . !

0

All Articles