Archived

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

Zorak

Linking __inline functions/methods in VC++6.0

Recommended Posts

Is there any way to work around the inline depth thingie in vc++6.0? The problem is that VC6.0 needs all the inline functions/methods in the header. I need them in a .cpp file or I will die out of code design sickness thingie. There must be a way to compile inline methods and let the linker find them even if they are in a .cpp file rather than the .h file. No? - Zorak - Neat Fella.

Share this post


Link to post
Share on other sites
hmmm....


// MyClass.h
#ifndef MYCLASS_H
#define MYCLASS_H
#define INLINE(x)
class MyClass
{
MyClass();
INLINE(void MyInlineFunction());

// inlines
#define MYCLASS_INLINES
#include "MyClass.cpp"
#undef MYCLASS_INLINES
};
#endif








// MyClass.cpp
#ifndef MYCLASS_INLINES
#include "MyClass.h"
MyClass::MyClass()
{
DoStuff();
}

// inlines
#else
inline void MyInlineFunction()
{
DoOtherStuff();
}
#endif



Don't listen to me. I've had too much coffee.

[edited by - sneftel on October 19, 2002 2:38:28 AM]

Share this post


Link to post
Share on other sites
Why do you have such a need for inline functions? You seem like you have a large amount, but inline functions are short, so it shouldn''t be much trouble to have them in the header. Have you profiled and seen that inlining all those functions would be A Good Thing (tm)?

Share this post


Link to post
Share on other sites
quote:
Original post by Neosmyle
Why do you have such a need for inline functions? You seem like you have a large amount, but inline functions are short, so it shouldn't be much trouble to have them in the header. Have you profiled and seen that inlining all those functions would be A Good Thing (tm)?


Its a vector class with a bunch of methods and asm functions to support it. And its getting big. Thanks for your help all.

- Zorak - Neat Fella.

[edited by - Zorak on October 19, 2002 8:02:36 AM]

Share this post


Link to post
Share on other sites
I always just done:


  
// in the header

inline void aMethod(...);

// in the cpp file

inline
void aMethod
{
...
}


It compiles fine and links okay but doesnt this work as an inline then?

Share this post


Link to post
Share on other sites
It''ll (almost certainly) only be inline to functions in that same CPP file that come after it. And I''ve seen linker errors arising when trying to use such a function from another file.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Share this post


Link to post
Share on other sites
Andy: your method works if only the .cpp file with the inline definition uses that header file. If that header is used by another class, your project won''t link.

Share this post


Link to post
Share on other sites