Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

dll-exporting a class defined with a template

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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

730 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