Thursday, 19 April 2018

c++ - separating constructor implementation with template from header file











My header file has



template 
class AA : public BB
{

public:
AA()
{ ... }


this is working fine. But I need to separate the constructor implementation from header file.



So in cpp, I have



template 

AA::AA()
{ ... }


When I compile this, it compiled but I get unresolved external symbol error. What am I missing here?


Answer



You can explicitly instantiate templates in your implementation file using :



template class AA;



this will generate a definition from a template, but it is of use only if you know what types your class clients will use


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...