-
June 27th, 2014, 02:04 PM
#1
extern templates
I am trying to use extern templates in VS 2010.
In most cases, people use extern templates purely as an optimization, but in my case I actually need them for correctness; in the header, the type instantiating the template is forward declared, so I want to defer instantiation to the source file where I have a complete type. Otherwise I'll get a compilation error. (It's valid for the template itself to be incomplete in the header, since it's just a pointer.)
Header:
Code:
class AbstractFolder;
extern template class Watcher<AbstractFolder>;
Source:
Code:
#include "abstractfolder.h"
template class Watcher<AbstractFolder>;
I've *almost* got it working, but I've run into this:
error C2960: 'Watcher<T>' : inconsistent explicit instantiations, a previous explicit instantiation specified 'extern template'
This seems like one of the stupidest errors ever, since my intent is clearly to override the "extern" and force instantiation at that point, but the compiler doesn't seem to want to let me do that.
Unfortunately it's impossible to do this in a source file where the header is not included, since the header with the extern declaration is included from abstractfolder.h (which is the reason forward declarations are needed in the first place).
Two questions. First, is it possible to make VS2010 do what I want here? Second, we may be upgrading to VS2013 soon; will it give me the behavior I want?
-
June 27th, 2014, 02:16 PM
#2
Re: extern templates
Oh, and the strange thing is that if I look up C2960, I get an unrelated error from VS6. There doesn't appear to be any documentation of this error message.
-
June 28th, 2014, 12:44 PM
#3
Re: extern templates
Hey. Mind if you send me your files your coding. I can check to see if I get the same issue. I can try to fix it and send you the fixed code.
thanks. Hope I can help.
-
June 28th, 2014, 06:33 PM
#4
Re: extern templates
Zip up a solution of a small sample that repros the problem so someone can try it out in VS 2013.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|