템플릿 클래스의 인스턴스를 만들 때 왜 해결되지 않은 외부 기호가 표시되는지 보는 데 문제가 있습니다.템플릿 ctor를 호출 할 때 확인되지 않은 외부 기호
링커 오류가 발생합니다 라인은 새로운 아래에 대한 호출입니다 :
Vbo<CustomVertex>* m_pVbo;
...
m_pVbo = new Vbo<CustomVertex> (
geometry.VertCount(),
geometry.Vertices(),
geometry.IndexCount(),
geometry.Indices()
);
// nb: geometry.Vertices return type is CustomVertex**
다음과 같이 VBO 클래스의 정의는 다음과 같습니다
template <typename T>
class Vbo : public glex
{
public:
Vbo();
Vbo(int nNumVerts, T** ppVertices, int nNumIndices, DWORD* pIndices);
Vbo(const Vbo<T> & rhs); // copy
Vbo<T> & operator=(const Vbo<T> & rhs); // assignment
~Vbo();
...
}
그리고 VBO 생성자의 구현 :
template <typename T>
Vbo<T>::Vbo(int nNumVerts, T** ppVertices, int nNumIndices, DWORD* pIndices) :
m_bInitialized (false),
m_nVboId (0),
m_nVboIdIndex (0),
m_nNumVertices (nNumVerts),
m_nNumIndices (nNumIndices),
m_ppVertices (ppVertices),
m_pIndices (pIndices)
{
glex::Load();
Initialize();
}
그리고 마지막으로 링커의 불만 사항 :
1> Actor.obj : 오류 LNK2019 : 해결되지 않은 외부 기호 "public : __thiscall Vbo :: Vbo (int, class CustomVertex * *, int, unsigned long *)"(0 0) $ Vbo @ VCustomVertex @@ ("InitializeGeometry @ Actor @@ AAE_NAAVIGeometry @@@ Z) 1> C : \ cuprofen \"QEE @ HPAPAVCustomVertex @ HPAK @ Z) "개인 : bool __thiscall 액터 :: InitializeGeometry (클래스 IGeometry &) 디버그 \ Cuprofen.exe : 치명적인 오류 LNK1120 : 해결되지 않은 외부 1 개
누군가 내 감독을 맡을 수 있습니까?
예, Vbo 생성자는 .cpp 파일에 정의되어 있습니다. 헤더 파일에 모든 것을 옮겨 보겠습니다. –
감사합니다. 재미있는 대답입니다. Vbo 코드를 헤더로 옮겨서 링커 오류가 사라졌습니다. "번역 단위"를 정의 할 수 있습니까? –
@freefallr : 느슨하게 말해서, 하나의 소스 파일과 거기에 포함 된 모든 것을 의미합니다. –