Got this in “char.h”
#ifndef _CHAR_H_
#define _CHAR_H_
#include <stdio.h>
template <unsigned int TChar>
class Char
{
public:
Char(){ *m_data=0; m_len=-1; }
private:
char m_data[TChar+1];
int m_len;
};
#endif
Now with this simple test :
#include "char.h"
void test(Char<TChar> &oo)
{
//...
}
int main(int argc, char *argv[])
{
Char<80> gg;
return 0;
}
I get with gcc :
TChar was not declared in that scope !?
I don’t understand, the declaration is in the .h ??
Thanks…
The full implementation of a template class must be in that template class’s header (otherwise you are likely to get a linker error).
The compiler needs to have access to the entire template definition (not just the signature) in order to generate code for each instantiation of the template, so you need to move the definitions of the functions to your header. (Inclusion Model).
You have placed the definition correctly. 🙂
However in
void test(Char<TChar> &oo)the compiler doesn’t know whatTCharis. Try addingtemplate <unsigned int TChar>above the definition