VS2008 external templates

Microsoft has an extension in which you can declare that the template instance will be external; therefore, it does not receive an implicit instance. At least this theory. I tried to reproduce this with code

#include <vector>

class Foo{
    int i;
public:
    virtual ~Foo();
};

extern template class std::vector<Foo>;

It gives me

warning C4231: nonstandard extension used : 'extern' before template 
explicit instantiation

However, nothing else happens: the program continues to bind find, although I use push_back (and dumpbin shows that push_back was created).

Only when I announce

extern template void std::vector<Foo>::push_back(const Foo&);

I get a linker error as expected.

So: how can I declare the entire instance (all members) explicit, preventing the implicit instantiation of the instance?

+3
source share
1 answer

, :

extern -, . , , .

vector::push_back() ( std::vector < > ) .

, , , extern - , , .

, , , extern -.

+6

Source: https://habr.com/ru/post/1776535/


All Articles