Re: "definition of dllimport function not allowed" error

Tech-Archive recommends: Speed Up your PC by fixing your registry




"Tom Widmer [VC++ MVP]" <tom_usenet@xxxxxxxxxxx> wrote in message
news:uPS%23$DKWGHA.3972@xxxxxxxxxxxxxxxxxxxxxxx
Julian wrote:
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

I'm surprised that even compiles. It doesn't make any sense to mark a
class template (or function template) as __declspec(dllimport), since it
isn't real code, just a template for creating real code. As such, there's
nothing to import!

What you can do is import/export particular specializations of templates,
which do consist of real code. For example, this exports a particular
template instantiation (and must be in the .cpp file I think).

template class __declspec(dllexport) Array<int>;

To import, you want, in the header:

template class __declspec(dllimport) Array<int>;

after the definition of Array<T>.

Tom

I think I get what you mean... let me try it out and get back to you.


.



Relevant Pages

  • Re: "definition of dllimport function not allowed" error
    ... class template as __declspec, ... isn't real code, just a template for creating real code. ... dll-interface to be used by clients of class 'type2' ... DLL-interface classkey 'identifier' ...
    (microsoft.public.vc.language)
  • Re: Is export "useless and broken"?
    ... >>the template header file. ... occur in real code is because the problem isn't fixed. ... Today, they aren't used, because of the dependencies they ...
    (comp.lang.cpp)
  • Re: "definition of dllimport function not allowed" error
    ... after fixing the code to get rid of the errors, I am still left with this one. ... I looked up the MSDN help files but it didn't help much. ... It doesn't make any sense to mark a class template as __declspec, since it isn't real code, just a template for creating real code. ...
    (microsoft.public.vc.language)
  • Re: Char Char1 style added when saving as dot template
    ... I managed to get rid of the unwanted style ... Text that was formatted with a paragraph style is formatted with a ... Note that it might be easier to recreate the template from a fresh ...
    (microsoft.public.word.formatting.longdocs)
  • Re: Styles incorrectly inheriting from another style in tables
    ... When I had tried to get rid of unneeded styles, Word decided to make the text ... Fortunately I had saved an iteration before I made this ... I'm considering starting from scratch with a new template and see ... You can mail me a sample doc, if you want to, and maybe a sentence or two in what way you think the doc is "hosed". ...
    (microsoft.public.word.newusers)