
VC7 dllimport regression problem
I surprised this ever worked - we have never officially supported code like
the following:
template<typename T>
class __declspec(dllexport) X {
Quote:
};
The reason being we did not think that anyone would want to have all
specializations of a class template be dllexport or import.
The "approved" way of doing this is the following:
1) Define the template:
template<typename T>
class X {
Quote:
};
2) Explicitly instantiate the specialization you want to dllexport/dllimport
template class __declspec(dllexport) X<int>;
Note: the error message is valid - if you declare a class to be dllimport
then you cannot define and of its method outside of the class: as they are
meant to be in the DLL.
--
Jonathan Caves
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. ? 2002 Microsoft Corporation. All rights
reserved.
http://www.microsoft.com/info/cpyright.htm.
Quote:
> sure, that's what I do in the original code. The problem
> is that VC7 wont compile the dllimport version.
> >-----Original Message-----
> >You have to define dllexport for the DLL and dllimport
> for the exe that uses
> >the dll..
> >> I've got a skeleton of a class hierarchy below that
> builds fine with
> >> VC6 SP5, but gives C2491 'defn of dllimport fn not
> allowed' compile
> >> errors at the marked lines on VC7 v13.0.9446. It
> seems to me that
> >> this is an erroneous error, because when I removed the
> definitions in
> >> the original file, the compiler complained that they
> were not there
> >> (error C4661). Can anyone suggest a workaround (other
> than not to use
> >> dllimport, I want the class defn to remain in only 1
> particular DLL as
> >> it was in VC6)?
> >> Thanks.
> >> ------------------------
> >> class _declspec(dllimport) ReferenceCount {
> >> };
> >> template<class Base>
> >> class _declspec(dllimport) RefCountProxy : public
> ReferenceCount {
> >> public:
> >> static void init_type();
> >> };
> >> template<class Base>
> >> class _declspec(dllimport) RefCountObj : public
> ReferenceCount,
> >> public Base {
> >> public:
> >> static void init_type();
> >> };
> >> template<class Base> // C2491 error here
> >> void RefCountProxy<Base>::init_type() {}
> >> template<class Base> // C2491 error here
> >> void RefCountObj<Base>::init_type() {}
> >.