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
Solved

Getting rid of dllimport warning messages for template classes

Posted on 2004-08-20
3
304 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
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

828 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