Thread: inlining functions

  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
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    ....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, 11:50 AM
  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, 01:41 PM
  4. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05: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