Skip to main content
gamedev.net
🔒 Locked 🤖 Godot

my template prob..?

Started by MTclip Oct 30, 2005 at 4:20 PM 1 replies 400+ views
Original Post
MTclip
MTclip
when i try to use my template class i recieve some errors I have obviously done something wrong.. but i cant find it here is the relevant part of my code..

/// MyArray.h
/// *** non error causing code clipped
template< class TYPE >
class MyArray
{
public:
	MyArray(void);								
	MyArray(const MyArray<TYPE>& a);					
	~MyArray(void);	
}	




/// MyArray.cpp
/// *** non error causing code clipped
template< class TYPE >
MyArray<TYPE>::MyArray(void)
{
	m_pData		= NULL; 
	m_nSize		= 0; 
	m_nMaxSize	= 0;
}

template< class TYPE >
MyArray<TYPE>::MyArray(const MyArray<TYPE>& a)
{
	for( int i=0; i < a.m_nSize; i++ ) 
		Add( a.m_pData );
}

template< class TYPE >
MyArray<TYPE>::~MyArray(void)
{
	RemoveAll();
}




/// main.cpp
#include "myarray.h"

int main(void)
{
	MyArray<float> arr;
}



while the class compiles fine if i dont try to use it here are the errors that are generated when i try to use "MyArray" (NOTE:: i get the same kind of error for any function i try to use) //// ERRORS MyArray error LNK2019: unresolved external symbol "public: __thiscall MyArray::~MyArray(void)" (??1?$MyArray@M@@QAE@XZ) referenced in function _main MyArray error LNK2019: unresolved external symbol "public: __thiscall MyArray::MyArray(void)" (??0?$MyArray@M@@QAE@XZ) referenced in function _main can any one point out my flaw? thanks
Imtiaz
Imtiaz
I've only used templates on a few occasions, and I believe I've come across a similar problem before. I think the solution ended being defining the member functions inside the header instead of a seperate cpp file.

Firstly do that, and then have a look at This website that should explain the 'why' part. (scroll down to end of the document)
MTclip
MTclip
Thanks!

works fine now

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.