Thread: inline function declaration

  1. #1
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879

    Arrow inline function declaration

    Hi, just a quick question. I'm running MSVC, and in my code, I have a header called CGeom.h:
    Code:
    #ifndef (...)
    #define (...)
    
    inline float degreesToRadians(float degrees);
    
    #endif
    In CGeom.cpp, I have the function definition for degreesToRadians:
    Code:
    inline float degreesToRadians(float degrees)
    {
         //do something
         return (result);
    }
    When I compiled this with the debug settings, it worked fine; under Release build, I got a unresolved external symbol for degreesToRadians. The problem went away when I just merged the definition and prototype(?) together in the header, instead of having them separate.

    Can anybody tell me why this happens?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    inline functions in C++ have internal linkage. You need to put the definition in the declaration in the .h file. A common way to do this is by putting all of your class declarations in the header and then at the end of the header putting #include "math.inl" and have all of your inline code in there. This isn't standard or anything but a lot of people do it. Hope this clears it up.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Thanks MrWizard, my confusion is no more
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    148
    Originally posted by MrWizard
    inline functions in C++ have internal linkage.
    No,
    7.1.2 Function Specifiers,Footnote 79
    The inline keyword has no effect on the linkage of a function.
    So they have the linkage they'd if inline was not specified. Linkage is always defined, the three choices are internal, external, or no linkage. An inline function with no explicit linkage spec has external linkage.

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Oh, great. So what's the problem then?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Well the new C++ standard says it has no effect. The old C++ standard says it has internal linkage. Guess which standard the old compilers go by.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM