AnsweredAssumed Answered

Use of templates with CodeWarrior for HCS12 V4.7

Question asked by JAY LARSON on Dec 14, 2008
Latest reply on Dec 15, 2008 by JAY LARSON
Hi,
 
I'm having trouble using a very simple template expansion using the HCS12 complier (latest version) Here is the code of what is not working:
 
Code:
#include <hidef.h>      /* common defines and macros */#include <mc9s12xdt512.h>     /* derivative information */#pragma LINK_INFO DERIVATIVE "mc9s12xdt512"class stackBase{public:    stackBase(int size, byte *start)     : bottom(start), top(start+size)    {    };    void Push(byte a)    {        *--top = a;    }    byte Pop()    {        return *top++;    }private:    byte *bottom;    byte *top;};template <int StackSize>class Stack : public stackBase{public:    Stack() : stackBase(StackSize, stackBytes)     {    };private:    byte stackBytes[StackSize];};    Stack<100> fred;Stack<101> sally;          void main(void) {    /* put your own code here */        fred.Push(1);        sally.Push(2);     for(;;) {} /* wait forever */    /* please make sure that you never leave this function */}

 
What happens is that I first get a warning in the template (C3603: Static 'Stack' was not defined.)
 
Then, I have a link error (L1822:  Symbol __ct__8Stack100Fv.4 in file ...)
 
I think that the code is fine.  If I make fred and sally both the same size, it works fine.  It seems that it can't expand 2 versions of the same template.
 
Is this a bug?
 
Cheers,
-Jay

Outcomes