[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

dll-exporting a class defined with a template

Posted on 1998-09-13
3
Medium Priority
?
247 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 200 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

834 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