Solved

dll-exporting a class defined with a template

Posted on 1998-09-13
3
223 Views
Last Modified: 2010-04-02
Hi,
The following code attempts to dll-export the class cBig; the MicroSoft Visual C++ 5.0 compiler generates the following warning:

warning C4251: 'mRange' : class 'TRange<long>' needs to have dll-interface to be used by clients of class 'CBig'

the code :
// Start of code
#define DllExport __declspec( dllexport )

template<class T> class TRange
{
.
.
}

class DllExport cBig
{
public:
.
.
protected:
    typedef TRange<long> CRange;
    CRange mRange;
}
// End of code

What should I do in order to resolve this warning? I've tried to insert an additional 'DllExport' almost everywhere in the code.
0
Comment
Question by:gil_mo
3 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1172584
I declared the template class as DllExport and added ";" to the ends of the classes like

template<class T> class DllExport TRange
   {
   } ;

   class DllExport cBig
   {
   public:
   protected:
       typedef TRange<long> CRange;
       CRange mRange;
   } ;

and it worked fine.
0
 

Author Comment

by:gil_mo
ID: 1172585
nietod,
warning persists if the class template isn't empty, e.g.

template<class T> class DllExport TRange
{
private:
    long a;
};

0
 
LVL 3

Accepted Solution

by:
xyu earned 50 total points
ID: 1172586
try to add this line before declaration of cBig

.
template class __declspec(dllexport) TRange<long>;
.
or
template<> class __declspec(dllexport) TRange<long>;

 it will help if TRange doesn't have outline implementation of the member functions like
template <class T> void TRange<T>::Foo() {...}

otherwise You'll receive on such a function warning like that..
"..dllexport assumed by default.." but its Ok... and You can live with it :) without any problem...

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

708 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

16 Experts available now in Live!

Get 1:1 Help Now