0

I have tried to write a template class. It seems that when I write the constructor in classname.cpp not in classname.h, then it could be compiled correctly.

Could someone explain this to me?

user3341953
  • 309
  • 1
  • 5
  • 14
  • Yes, if the compiler does not support the `export` keyword. – songyuanyao Mar 10 '14 at 02:08
  • 1
    @songyuanyao, That was removed from the C++11 standard. – chris Mar 10 '14 at 02:09
  • anyway what should I do if I want to write them separately – user3341953 Mar 10 '14 at 02:35
  • @chris Sorry I did not know that. So, now we really have to write all defination of a template in head file? (Although rare compilers support `export` so we have to do it in fact) – songyuanyao Mar 10 '14 at 02:39
  • @songyuanyao, user: Well, some people like to make .tpp or .tcc or whatever files for template definitions that they include at the bottom of the header. It's not that they have to be implemented in the header, but they can't be in a different translation unit. – chris Mar 10 '14 at 02:44
  • you mean #inlcude ".cpp" in the last of the head file, but if I did this. It says there is a redefinition – user3341953 Mar 10 '14 at 02:48

0 Answers0