Use of templates with CodeWarrior for HCS12 V4.7

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Use of templates with CodeWarrior for HCS12 V4.7

2,247 次查看
Jay
Contributor I
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
标签 (1)
标记 (1)
0 项奖励
回复
2 回复数

874 次查看
stanish
NXP Employee
NXP Employee
Hi Jay,

I don't have knowledge of C++ but since CodeWarrior C++ compiler has some limitations related to templates I'd suggest you to check Compiler manual ("<CodeWarrior Home Directory>\Help\PDF\Compiler_HC12.pdf", Section "Known C++ Issues in the HC(S)12 Compilers", page 691-692).

Stanish
0 项奖励
回复

874 次查看
Jay
Contributor I
Hi,
 
Thanks for the reply.  I could not find any applicable compiler limitations in the documentation.  Really, the template instantiation that I'm doing is very simple.  It should be handled, if the compiler supports templates correctly.  I'm at a loss as to why it works with a single size, but not 2 or more different sizes. 
 
Cheers,
-Jay
0 项奖励
回复