Template Class [modified]
-
I am using templates for a class for the first time and I cannot figure out what I am doing wrong. Any help would be greatly appreciated. This code will generate LNK2019 Unresolved External
// Test AssocArray
AssocArray<Vector3> myArray;Class Definition
template <class TValue>
class AssocArray
{
public:
AssocArray();
AssocArray(int size, int resizeBy);int GetCount() { return m\_nItems; } void SetNewSize(int size, bool copy = true); void IncreaseSize(int size, bool copy = true); TValue operator \[\](int i); TValue operator \[\](string s);
private:
int m_nItems;
int m_nMaxItems;
int m_nResizeBy;KeyValuePair<string, TValue>\* m\_array;
};
Class Constructor
template <class TValue>
AssocArray<TValue>::AssocArray()
{
m_nItems = 0;
m_nMaxItems = 2;
m_nResizeBy = 2;
m_array = new KeyValuePair[2];
}modified on Sunday, May 3, 2009 5:28 AM
-
I am using templates for a class for the first time and I cannot figure out what I am doing wrong. Any help would be greatly appreciated. This code will generate LNK2019 Unresolved External
// Test AssocArray
AssocArray<Vector3> myArray;Class Definition
template <class TValue>
class AssocArray
{
public:
AssocArray();
AssocArray(int size, int resizeBy);int GetCount() { return m\_nItems; } void SetNewSize(int size, bool copy = true); void IncreaseSize(int size, bool copy = true); TValue operator \[\](int i); TValue operator \[\](string s);
private:
int m_nItems;
int m_nMaxItems;
int m_nResizeBy;KeyValuePair<string, TValue>\* m\_array;
};
Class Constructor
template <class TValue>
AssocArray<TValue>::AssocArray()
{
m_nItems = 0;
m_nMaxItems = 2;
m_nResizeBy = 2;
m_array = new KeyValuePair[2];
}modified on Sunday, May 3, 2009 5:28 AM
-
Error 1 error LNK2019: unresolved external symbol "public: __thiscall AssocArray<class Vector3>::AssocArray<class Vector3>(void)" (??0?$AssocArray@VVector3@@@@QAE@XZ) referenced in function "public: void __thiscall EngineRoot::InitializeLater(void)" (?InitializeLater@EngineRoot@@QAEXXZ) EngineRoot.obj Error 2 fatal error LNK1120: 1 unresolved externals
modified on Sunday, May 3, 2009 9:39 PM
-
Error 1 error LNK2019: unresolved external symbol "public: __thiscall AssocArray<class Vector3>::AssocArray<class Vector3>(void)" (??0?$AssocArray@VVector3@@@@QAE@XZ) referenced in function "public: void __thiscall EngineRoot::InitializeLater(void)" (?InitializeLater@EngineRoot@@QAEXXZ) EngineRoot.obj Error 2 fatal error LNK1120: 1 unresolved externals
modified on Sunday, May 3, 2009 9:39 PM
Is the constructor in the same file as the class definition? (Hint: it isn't.) (If you're wondering why it doesn't give you a compilation error, it's because the compiler doesn't know if you have a class template specialization defined somewhere.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
-
Is the constructor in the same file as the class definition? (Hint: it isn't.) (If you're wondering why it doesn't give you a compilation error, it's because the compiler doesn't know if you have a class template specialization defined somewhere.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
-
Constructor and all member functions are in a separate file to the definition. There is no template specialization in the code.
That's my point; put everything into one file. By their nature, template classes are nothing but definition.
Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
-
That's my point; put everything into one file. By their nature, template classes are nothing but definition.
Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke