Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why the C4251 warning?

1 view
Skip to first unread message

Doug Sauder

unread,
Jul 11, 2001, 11:16:56 AM7/11/01
to
In one of the classes in my DLL I have a private member
that is an instance of a vector from the standard C++
library. When this class is compiled, I get this warning
from the compiler:

warning C4251: 'm_Addrs' : class 'std::vector<class CAddr
*,class std::allocator<class CAddr *> >' needs to have dll-
interface to be used by clients of class 'CAddrList'

Because the member variable is private, I don't see why
the compiler would care about it being "used by clients of
class CAddrList". But, considering that that is the case,
I don't know how I would instantiate a template class and
declare it as part of a DLL interface (using __declspec
(dllexport)).

Does anyone understand this enough to explain it and solve
it?

Doug Sauder

Doug Harrison [MVP]

unread,
Jul 12, 2001, 11:49:53 AM7/12/01
to
Doug Sauder wrote:

You might try exporting the specializations you need, but the problem
with that, of course, is that you're probably always needing new
specializations. You can also try ensuring that no inline member
functions use the member provoking the C4251. This includes
compiler-generated default ctor, copy ctor, dtor, and assignment
operator, if any. The member in question is private, so the compiler
could assume that if no inline functions use it, and the class has no
friends, client context doesn't have access to it. But I don't know if
that helps, because I always disable this warning, which is usually
spurious. The compiler will instantiate the template when compiling
code that uses it (the "clients"), so if you don't mind each
dynamically linked component having its own copy of the generated
template code, you should be fine. If you would like to share one copy
among all the dynamically linked components, you'll need to explicitly
instantiate the specializations you need and export them from some
common DLL everybody links to. For example, this is what MS does with
basic_string<char>, basic_string<wchar_t>, and other specializations,
which you'll find in msvcp60.dll.

0 new messages