Thread: Inline Definitions and Declarations?

  1. #1
    Student legit's Avatar
    Join Date
    Aug 2008
    UK -> Newcastle

    Inline Definitions and Declarations?

    Hey programmers of C Board
    I have a question about inline functions. If I declare a function inline, do I have to define it as inline also? I'll demonstrate:

    class Someclass
        inline void vSomeFunc();
    ...and in my .cpp file I have:

    inline void SomeClass::vSomeFunc()
        std::cout << "Some output" << std::endl;
    ... so in my source file, do I need to define the function vSomeFunc as inline if I have already declared it as inline?

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    1) The compiler needs to see the definition of an inline function. You need to put the implementation into the header file.

    2) Once a function is declared inline once, it sticks. Redeclarations won't change that. Declare a function first non-inline and then inline, however, and it becomes inline. Define a function non-inline, and then declare it inline, and the program is ill-formed, as per Core Issue 317.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. Declarations and definitions in C
    By jack1234 in forum C Programming
    Replies: 8
    Last Post: 12-17-2007, 11:24 AM
  3. Memory Leak
    By jtullo in forum C Programming
    Replies: 7
    Last Post: 12-11-2006, 11:45 PM
  4. help on declarations
    By robasc in forum C Programming
    Replies: 9
    Last Post: 03-05-2005, 01:50 PM
  5. help writing function definitions
    By jlmac2001 in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2003, 09:44 PM