CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2003
    Location
    not-so-Great Britain
    Posts
    178

    LNK2019 if inline fine if not

    Subject basically sums it up. I have a class and the .h is code free and in the .cpp file for that class I use inline on the function definitions I want inlined. Main.cpp includes "myclass.h" and does some tests on the class. Everytime I call a function I have specified as inline I get a LNK2019 unresolved external. If I remove the inline specifier the code compiles and runs perfectly but not as quick as I'd like. So how do you keep .h code free and tell the compiler (msvc7) to inline the functions? Do the inline functions have to be in the header file ? I checked help files but they were useless only showing single-file code.
    Hungarian notation is the bane of self documenting code.
    Forget all fancy tricks with operator precedence. Code should be easily readable.
    May the BOOST be with you.
    Good free E-Books thanks to Bruce Eckel.

  2. #2
    Join Date
    Jan 2004
    Posts
    20

    Re: LNK2019 if inline fine if not

    Originally posted by Improving
    Do the inline functions have to be in the header file ?
    short answer, yes. the body of the inlined function has to be in the same scope as the place where it gets inlined. (when in doubt, check with the standard: 3.2.4. An inline function shall be defined in every translation unit in which it is used)

  3. #3
    Join Date
    Jan 2004
    Posts
    206
    Definition of the inline functions need to be in the same file as the declaration of the class which contain the inline functions.

    Alternatively, u can define these functions within the class declaration without using the keyword inline, serve the same purpose anyway.

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Take a look at the following FAQ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured