Solved

Getting rid of dllimport warning messages for template classes

Posted on 2004-08-20
3
275 Views
Last Modified: 2010-04-01
Hi,

I'm tired of stuff like this:

// File: foo.h

class __declspec(dllimport) foo
{
  int x;
  vector<int> xs;
};

When including foo.h you will get a bunch of warnings about vector<> (or it's allocator) not being dllexported:

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\vector(35) : warning C4251: 'std::_Vector_val<_Ty,_Alloc>::_Alval' : class 'std::allocator<_Ty>' needs to have dll-interface to be used by clients of class 'std::_Vector_val<_Ty,_Alloc>'

Of course, vector isn't dllexported because it is a template class, and its implementation is entirely contained within the relevant header files.  Is there some way to avoid these warning?

Unacceptable solutions are:

(1) using #pragma warning(disable: xxxx) or similar to simply surpress the errors
(2) changing any of the standard header files
(3) Changing the dllexport nature of the client class (foo), for example by only exporting specific functions



0
Comment
Question by:travd
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
Comment Utility
As I just posted the same in another Q: Check out http://support.microsoft.com/default.aspx?scid=kb;en-us;168958 ("How To Exporting STL Components Inside & Outside of a Class") and http://support.microsoft.com/default.aspx?scid=kb;en-us;172396 ("PRB: Access Violation When Accessing STL Object in DLL")

Templates and DLLs can cause problems if you do not offer proper access (via e.g interfaces) to these objects, which better only "live" inside the modukes they're created in.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now