Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

gimp

Link doesn't like my inlines

This topic is 6310 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Maybe I''m doing something wrong here. In my header file I define a function like this : inline float Sqr (float a_Value); in the cpp inline float Sqr (float a_Data) { return a_Data*a_Data; } When I attempth to use this in my code ie call Sqr from a function somewhere I get linking problems. When both interface and implementation are the same this should work right. I also would like to apologise for asking a question like this. I can''t get the serch engine working (Timeouts) and I''ve scrolled waayy back Many thanks Chris

Share this post


Link to post
Share on other sites
Advertisement
quote:

"You’ll almost always want to put inline definitions in a header file. When the compiler sees such a definition, it puts the function type (the signature combined with the return value) and the function body in its symbol table. When you use the function, the compiler checks to ensure the call is correct and the return value is being used correctly, and then substitutes the function body for the function call, thus eliminating the overhead. The inline code does occupy space, but if the function is small, this can actually take less space than the code generated to do an ordinary function call (pushing arguments on the stack and doing the CALL).


An inline function in a header file has a special status, since you must include the header file containing the function and its definition in every file where the function is used, but you don’t end up with multiple definition errors (however, the definition must be identical in all places where the inline function is included)."


another quote from ISO/IEC 14882, 7-1-2-3:

"A function defined within a class definition is a inline function, The inline specifier shall not appear on a block scope function declaration."

i dunno what''s "a block scope" here, i guess it''s a normal function and seperated from declaration and shall be complied into a .obj file.

hope this is helpful.

------------------------------
Dedicate to nobody, I''m nobody

Share this post


Link to post
Share on other sites
What ed9er is trying to say is: move the code from the CPP file and place it in the header file. Include the header in whatever file you use the function in and you should be good to go.

Regards,
Jumpster

EDIT: I may be wrong here but I think the term block scope means something like this...


int main( void )
{
inline void Hello( void ) { cout << "Hello!";

for (int x=0; x<10; x++)
Hello();

return 0;
}


Please, If I'm wrong, somebody please tell me because I would really like to know. Thanks.

Edited by - Jumpster on February 13, 2001 8:43:02 AM

Share this post


Link to post
Share on other sites
Gimp,

Here are a couple of past articles that you may find useful:

Inline Problem Article 1
Inline Problem Article 2

I came across this problem and, as the previous posters say, moving your function definition from the cpp file to the header file will solve it.

I created a class and, once I''d tested it, decided to make a lot of the member functions inline by adding the inline keyword to the start of the function definitions in the cpp file. Everything was ok except for a couple of functions, which gave me the "unresolved external" error. It turned out that this was due to them being called from within a "for" loop in the main program.

I don''t quite understand why this should prevent a function from being inline, and why, even if it does, it should cause an error. Can anyone explain this?

Moot

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!