inlining functions

This is a discussion on inlining functions within the C++ Programming forums, part of the General Programming Boards category; When I inline a function it gives me an error that there is an undefined reference to the functions. It ...

  1. #1
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853

    inlining functions

    When I inline a function it gives me an error that there is an undefined reference to the functions. It is simply a get function, sth like this
    Code:
    inline obj myClass::getVar()
    {
        return val;
    }
    Even if I inline it on its delcaration
    Code:
    myClass {
    ...
       inline obj getVar();
    }
    I get the same error

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,270
    Did you put the implementation in a separate .cpp file? It can't be there. It needs to be in the same header as the declaration (or in SOME header that gets included everywhere the function is called)
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Yes, I did. Thanx, will change it. Can you explain shortly the reason?

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    ....Can you explain shortly the reason?
    How about we ask what you think inline is telling the compiler? I bet you will be able to answer your own question if you read your help file and/or do some research.

    Incidentally I understand this may be for an assignment or for learning purposes but I normally avoid inline functions. The main problem with them is it is only a 'hint' to the compiler to inline the function. As such the compiler can opt not to inline it and thus all efficiency you thought you were gaining is lost. The main crux of the problem is it is very hard to determine which functions the compiler will inline and which ones it will not. Because of this guessing game I avoid them.
    Last edited by VirtualAce; 12-03-2009 at 10:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 12:50 PM
  2. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  3. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 02:41 PM
  4. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 06:39 AM
  5. Problems with inline functions in visual c++
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2002, 03:14 AM

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