LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-17-2007, 02:27 PM   #1
mfurnanz
LQ Newbie
 
Registered: Jan 2007
Posts: 5

Rep: Reputation: 0
C++ inline - where to specify?


I'm trying to verify that my inline specification is correct:

If have a function declared as inline both in the class header file in the .cpp file where it is defined, I get the following warning when compiling any module that calls this function:

Warning from compilation:

test.h:977: warning: inline function `long myClass::getState() const' used but never defined


Header file declaration:

inline long getState();


Function definition in C++ module:

inline long myClass::getState() {
return currentState;
}


When I remove "inline" from the header prototype I get no warning:

I assume this is correct (?) Is there any way to verify that it is actually inlined by looking at the object file using nm or something?

Thanks for any help,
Mike
 
Old 01-17-2007, 03:00 PM   #2
Four
Member
 
Registered: Aug 2005
Posts: 298

Rep: Reputation: 30
see http://www.dsprelated.com/groups/c6x/show/7531.php

To summerize: You will need to move the function definition to the header file. Or what you can do is in the .cpp file or similar where the inline function is encapsule it with

#ifdef INLINE_INCLUDE
inline functions ....
#endif

#ifndef INLINE_INCLUDE
non-inline functions...
#endif

then in your header file
#define INLINE_INCLUDE
#include "cppfile"
#undefine INLINE_INCLUDE

and remove the prototype in the header file. I think that should work.
 
Old 01-17-2007, 03:14 PM   #3
mfurnanz
LQ Newbie
 
Registered: Jan 2007
Posts: 5

Original Poster
Rep: Reputation: 0
...interesting, I hadn't thought of that--isn't that kind of unconventional in that it goes against the strictest sense of what a header file is?

If I remember correctly, i think i read to include the function definition in body of the class definition. Sound okay too?

Thanks again,
Mike
 
Old 01-17-2007, 03:29 PM   #4
mfurnanz
LQ Newbie
 
Registered: Jan 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Sorry, I get it. What your mentioned in your initial reply (2) is exactly what I was talking about and didn't realize:

"include the function definition in body of the class definition"...

I probably should have said the "class declaration" to be more accurate.

Thanks,
Mike
 
  


Reply

Tags
inline



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Snort inline enyawix Linux - Networking 0 09-24-2004 03:10 PM
[SOLVED] C++ inline function: Use or don't use? druuna Programming 7 09-13-2004 04:08 PM
assemby inline linuxanswer Programming 2 05-02-2004 07:59 AM
C++ inline functions Slickfty2 Programming 12 04-23-2003 07:13 PM
inline AutoComplete hmorrow General 2 06-20-2001 04:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration