Original Post
I've never used templates before, so I decided to test them out with this VERY simple console program. Here's the code:
Container.h:
#ifndef _CONTAINER_H_
#define _CONTAINER_H_
template <class T> class Container
{
public:
Container(T *);
~Container();
T & GetObject() const;
protected:
T * pObject;
};
#endif //_CONTAINER_H_
Container.cpp:
#include "Container.h"
template <class T> Container<T>::Container(T * pInitObject):
pObject(pInitObject)
{
}
template <class T> Container<T>::~Container()
{
delete pObject;
}
template <class T> T & Container<T>::GetObject() const
{
return *pObject;
}
TemplateTest.cpp:
#include "container.h"
#include <iostream.h>
int main()
{
int i = 10;
Container<int> container(&i);
cout << container.GetObject();
return 0;
}
That's it. Just a simple little test. My linker tells me all the member functions for Container<int> are unresolved externals. I thought the compiler was supposed to define that for you. That's the point of a template, right? I double and triple checked that Container.cpp was included in my project and that the member fuctions' declarations matched the definitions. I know it must be something obvious.
Edited by - scrawny on 4/29/00 1:14:35 AM