尝试使用使用模板的方法时出现链接错误 来自其他静态库

问题描述 投票:0回答:1

我正在尝试使用在链接的静态库中的类中定义的方法,该方法使用template<typename T>

我尝试从方法中删除模板,突然间我可以构建。我也尝试过在同一个类中调用其他方法,并且构建正常。

这是代码:

Entity.h

template<typename T>
T* GetComponent() 
{
    if (m_ComponentBitSet[GetComponentTypeID()<T>])
    {
        return m_ComponentArray[GetComponentTypeID()<T>];
    }
    else
    {
        return nullptr;
    }
}

SpriteBatch.cpp

void SpriteBatch::Draw(const std::unique_ptr<LampEntity::IEntity>& pEntity)
{
   if(auto* pSrite = pEntity->GetComponent<LampEntity::SpriteComponent>()) //The link error happens
   {
       //using the pointer to draw
   }
}

我得到一个引用GetComponent方法的LNK2019未解析的外部符号。当我从方法中删除模板时,它可以正常运行。

我正在将LampEntity.lib链接到Lamp.lib,后者随后链接到沙箱。该问题出现在引用LampEntity.lib的Lamp.lib中。

可能是什么问题?

c++
1个回答
0
投票

好的,因此问题在重新启动计算机后以某种方式神奇地修复了自身...

© www.soinside.com 2019 - 2024. All rights reserved.