Inline function create linker errors
When I try creating inline functions I get weird linking errors:
This is defined in the header:
inline int DoSomething(void);
And this is in the source:
inline int DoSomething(void)
{
}
For some weird reasons I keep getting:
File.obj : error LNK2001: unresolved external symbol "int __cdecl DoSomething(void)" (?DoSomething@@YAHHHHGPAGH@Z)
Debug/Test.exe : fatal error LNK1120: 1 unresolved externals
Anyone ?
The road to success is always under construction
Goblineye EntertainmentThe road to success is always under construction
Actually somebody has already posted something similar here at gamedev, but I don''t mind responding to it again.
You say you prototype the function in a header file (with the inline keyword added) and then you define that function in some source file, by what you say..... Well, when you define a function to be inline you ""must"" put execution code right after you prototype the function.
So your pseudo-code would be:
inline int DoSomething(void)
{
}
The error you keep on getting is your linker telling you that it doesn''t see your implementation code for the prototype you defined in the header.
So take out the function from the header, or copy the implementation code to the header and get rid of the "inline int Do..." in the source file.
Being punctual is only making your mistake on time...
Murphy
You say you prototype the function in a header file (with the inline keyword added) and then you define that function in some source file, by what you say..... Well, when you define a function to be inline you ""must"" put execution code right after you prototype the function.
So your pseudo-code would be:
inline int DoSomething(void)
{
}
The error you keep on getting is your linker telling you that it doesn''t see your implementation code for the prototype you defined in the header.
So take out the function from the header, or copy the implementation code to the header and get rid of the "inline int Do..." in the source file.
Being punctual is only making your mistake on time...
Murphy
Being punctual is only making your mistake on time...Murphy1 to 3 chefs make a good restaurant 100 chefs makes a McDonaldsTim Sweeney
I don''t think that is exactly right either.
Here is how I like to do my inline functions and as far as I can tell they do get inlined. The only way to tell that they are inlined is to look at the ASM listing. Does anyone know a better way to know if they do or don''t get inlined?
This is in the class definition. I hate inline functions there cause it is so, um, messy. (I just hope I''m right about them getting inlined. )
This is below the class definition in the header file.
The key is that the function prototype and the function must be in the header file. They cannot be split up. Templates are like this, as well. I believe that the next set of standards allow templates and inline functions to be split up in the standard header file and code file method.
Mike Roberts
aka milo
mlbobs@telocity.com
Here is how I like to do my inline functions and as far as I can tell they do get inlined. The only way to tell that they are inlined is to look at the ASM listing. Does anyone know a better way to know if they do or don''t get inlined?
This is in the class definition. I hate inline functions there cause it is so, um, messy. (I just hope I''m right about them getting inlined. )
int DoSomething(void);
This is below the class definition in the header file.
inline int ClassX::DoSomething(void){}
The key is that the function prototype and the function must be in the header file. They cannot be split up. Templates are like this, as well. I believe that the next set of standards allow templates and inline functions to be split up in the standard header file and code file method.
Mike Roberts
aka milo
mlbobs@telocity.com
After declaring the function and defining it in the header, all is well in C++ world
The road to success is always under construction
The road to success is always under construction
Goblineye EntertainmentThe road to success is always under construction
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement