Solved

dll-exporting a class defined with a template

Posted on 1998-09-13
3
226 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

895 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

18 Experts available now in Live!

Get 1:1 Help Now