I am rebuilding my code (which was initially built using VC6 with no errors)
using .NET2005.
after fixing the code to get rid of the errors, I am still left with this
one.
I have simplified my code (see below) to reproduce the error:
error C2491: 'Array<T>::isIn' : definition of dllimport function not allowed
I looked up the MSDN help files but it didn't help much. can someone tell me
what I need to do to fix this
thanks,
Julian.
template <class T> class __declspec(dllimport) Array
{
private:
int numElements;
protected:
T **array;
public:
Array();
Array(int size, int inc=10);
~Array();
int isIn(const T &);
};
template <class T> int Array<T>::isIn(const T &t)
{
int i;
for(i=0;i<numElements;i++)
if(t==(*array
)) return i;
return -1;
}
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}

"definition of dllimport function not allowed" error
Alagappapillai
One more probable reason can be you may try to export the functions. But due to some switch definition combination or mistake if somebody uses __declspec(_dllimport) inplace of __declspec(dllexport) then this error comes.
Probably solution is check whether you are importing/exporting the class from given source.
Pl let me know still you have questions at girish.patel@rsystems.com
John Moore999
BPMIlls2001
The error message is self explanatory. When you specify __declspec(dllimport), what you are telling the compiler is to import this class or function from elsewhere. So you cannot define a body for it. Are you sure you don't mean to use dllexport there
kabuki
Hmm, I thought you couldn't compile template classes into an object before hand because it wouldn't have the functions for all the types.
The stl library isn't compiled, it's all in the headers for the stl, like iostream and such. Since you will be shipping the entire template class around in the header there is no point in having the __declspec(dllimport) there so just get rid of it. You don't need it with template classes.
The way you need to use a template class is to define it in one header file, all the methods need to be coded in the header file too. Once you have that then you include that header file in all code files which use your template class. You should find that it will then work.
Sianoosh
template <class T> class __declspec(dllimport) Array;
but when I do this, I cannot use this template in the driver program.. it says:
error C2079: 'test' uses undefined class 'Array<T>'