Inline Definitions and Declarations?

This is a discussion on Inline Definitions and Declarations? within the C++ Programming forums, part of the General Programming Boards category; Hey programmers of C Board I have a question about inline functions. If I declare a function inline, do I ...

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

    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:

    SomeHeader.h
    Code:
    class Someclass
    {
    public:
        inline void vSomeFunc();
    };
    ...and in my .cpp file I have:

    SomeCppFile.cpp
    Code:
    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
    Posts
    8,893
    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!
    CornedBee

    "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, 10:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21