MSVC ++ Linker warning when using PIMPL idiom in C ++ / CLI

I am writing a .NET assembly using C ++ / CLI (version 9.0) and I would like to use the PIMPL idiom to avoid putting unnecessary things in my public header. Unfortunately, when I try to post a declaration to declare a class and then use a tracking descriptor for it, I get a 4248 "Linker" message:

warning LNK4248: unresolved token typeref (0100000E) for 'MyNamespace.PrivateClass'; image may not work

It looks like I am using the CLI class or my own class for the implementation class.

Below is a sample code:

namespace MyNamespace
{
    ref class PrivateClass; // forward dec

    ref class MyPublicClass
    {
    private:
        PrivateClass^ m_Imp;
    };
}

      

Microsoft's explanation for the warning is not very informative, unfortunately.

+1


source to share


2 answers


I think you are using two technologies that don't mix well:

The natural application for pimpl is to avoid having to constantly change the header files, thereby causing large recompilations in large C ++ projects.

The natural application for C ++ / cli is to write skinny little snippets of interaction, and the default VS behavior for these projects is to put all the code in headers, which is about as anti-pimpl as you can get.



If you are writing something large enough to warrant a pimpl, then I would not recommend C ++ / cli. If you're writing something small enough to make C ++ / cli fit, I wouldn't bother with pimpl.

YMMV, of course, but that would be my take on ...

+2


source


Upon further digging and reflecting, I found that in some respects .NET doesn't need to support PIMPL in the same way as C ++, since you can mark a class private to assembly - this essentially has the same effect, in some way sense. However, often the PIMPL idiom is used to hide headers that you don't want the client to be able to compile. But of course .NET assemblies are not included like headers are for C ++, so I guess there really isn't a problem there.



+1


source







All Articles