How to use the "extern template" with a nested class that is used by the template in the same class?

First, some context: I'm trying to use the Pimpl idiom in the way Herb Sutter introduced it in his GotW # 101 solution . This will look in the header file:

#include "pimpl_h.h"
class widget {
    class impl;
    pimpl<impl> m;
    // ...
};

The implementation will look like this:

#include "pimpl_impl.h"
class widget::impl {
    // ...
};

The problem I'm trying to solve occurs when a class using this method uses another Pimpl class for its own implementation. It includes "pimpl_impl.h", so the compiler (in my case VC ++ 2013) gets knowledge about a specific template for pimpl <impl>another class and tries to implicitly create it, which, of course, leads to compilation errors, as I do not know about the implementation of this class.

, "extern template" ++ 11 :

#include "pimpl_h.h"
class widget {
    class impl;
    pimpl<impl> m;
    // ...
};
extern template pimpl<widget::impl>;

, , , widget::impl, . , IntelliSense :

Error: 'extern template' cannot follow explicit instantiation of class "pimpl<widget::impl>"

" " ,

#include "pimpl_h.h"
class widget {
    class impl;
    extern template pimpl<impl>;
    pimpl<impl> m;
    // ...
};

. :

IntelliSense, ? , V++ ++?

++, ?

+4
1

, . 14.7.2.11 ,

, , .

, , IntelliSense. , : "... ...". , , widget. , IntelliSense. ,

, , , (14.7.1) , ; , .

- () .

, . , pimpl<impl>, pimpl_impl.h. extern template pimpl<impl> , , , . , pimpl<impl> extern template .

+2

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


All Articles