V
Victor Hannak
This is my first try at using a template class, and I am getting linker
errors that I can't figure out:
[Linker Error] Unresolved external
'ShapeStackClass<CircleClass>::GetStackSize()' referenced from
C:\PROGRAM1\MYCLASS.OBJ.
[Linker Error] Unresolved external
'ShapeStackClass<SquareClass>::GetStackSize()' referenced from
C:\PROGRAM1\MYCLASS.OBJ.
This is how I have set up my template class:
ShapeStackClass.h
--------------------
template <class ShapeType>
class ShapeStackClass {
public:
ShapeStackClass(unsigned short MaxStackSizeIn);
~ShapeStackClass();
unsigned short GetStackSize();
....
ShapeStackClass.c
--------------------
#include "ShapeStackClass.h"
template <class ShapeType>
ShapeStackClass<ShapeType>::ShapeStackClass(unsigned short MaxStackSizeIn) {
StackSize = 0;
MaxStackSize = MaxStackSizeIn;
}
template <class ShapeType>
ShapeStackClass<ShapeType>::~ShapeStackClass() {
EmptyStack();
}
template <class ShapeType>
unsigned short ShapeStackClass<ShapeType>::GetStackSize() {
return(StackSize);
}
....
I am creating and using this class as follows where Circles and Squares are
derived from the Shape class :
MyClass.h
-----------
#include "ShapeStackClass.h"
class MyClass {
public:
MyClass();
~MyClass();
unsigned short MyClass::GetSize();
private:
ShapeStackClass<CircleClass> *CircleStack;
ShapeStackClass<SquareClass> *SquareStack;
}
MyClass.c
-----------
MyClass::MyClass() {
CircleStack = new ShapeStackClass<CircleClass>(5);
SquareStack = new ShapeStackClass<SquareClass>(5);
}
MyClass::~MyClass() {
delete CircleStack;
delete SquareStack;
}
unsigned short MyClass::GetSize() {
return(CircleStack->GetStackSize()+SquareStack->GetStackSize());
}
What am I doing wrong?
errors that I can't figure out:
[Linker Error] Unresolved external
'ShapeStackClass<CircleClass>::GetStackSize()' referenced from
C:\PROGRAM1\MYCLASS.OBJ.
[Linker Error] Unresolved external
'ShapeStackClass<SquareClass>::GetStackSize()' referenced from
C:\PROGRAM1\MYCLASS.OBJ.
This is how I have set up my template class:
ShapeStackClass.h
--------------------
template <class ShapeType>
class ShapeStackClass {
public:
ShapeStackClass(unsigned short MaxStackSizeIn);
~ShapeStackClass();
unsigned short GetStackSize();
....
ShapeStackClass.c
--------------------
#include "ShapeStackClass.h"
template <class ShapeType>
ShapeStackClass<ShapeType>::ShapeStackClass(unsigned short MaxStackSizeIn) {
StackSize = 0;
MaxStackSize = MaxStackSizeIn;
}
template <class ShapeType>
ShapeStackClass<ShapeType>::~ShapeStackClass() {
EmptyStack();
}
template <class ShapeType>
unsigned short ShapeStackClass<ShapeType>::GetStackSize() {
return(StackSize);
}
....
I am creating and using this class as follows where Circles and Squares are
derived from the Shape class :
MyClass.h
-----------
#include "ShapeStackClass.h"
class MyClass {
public:
MyClass();
~MyClass();
unsigned short MyClass::GetSize();
private:
ShapeStackClass<CircleClass> *CircleStack;
ShapeStackClass<SquareClass> *SquareStack;
}
MyClass.c
-----------
MyClass::MyClass() {
CircleStack = new ShapeStackClass<CircleClass>(5);
SquareStack = new ShapeStackClass<SquareClass>(5);
}
MyClass::~MyClass() {
delete CircleStack;
delete SquareStack;
}
unsigned short MyClass::GetSize() {
return(CircleStack->GetStackSize()+SquareStack->GetStackSize());
}
What am I doing wrong?