Use of templates with CodeWarrior for HCS12 V4.7

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Use of templates with CodeWarrior for HCS12 V4.7

2,282件の閲覧回数
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 返答(返信)

909件の閲覧回数
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 件の賞賛
返信

909件の閲覧回数
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 件の賞賛
返信