Solved

Getting rid of dllimport warning messages for template classes

Posted on 2004-08-20
3
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 11857349
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

756 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