forceinline outside of class definiton?

Hey,

Is it not possible to have a function declared forceinline_ and define it outside of the class definition.

With the standard inline it works and it's recommended/preferred to have it outside of the class definition in the headerfile.

.h

1
2
3
4
5
6
class MyClass
{
 void func();
};

inline void MyClass::func(){..}


but somehow with forceinline it doesn't work:

1
2
3
4
5
6
7
8
9
10
11
12
13
//check platform
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#    define FORCEINLINE __forceinline
#else
#    define FORCEINLINE __attribute__((always_inline))
#endif

class MyClass
{
 void func();
};

FORCEINLINE void MyClass::func() {..}


as far as i know it's only possible to have function definitions in the header(outside of class def.) with the c++ inline keyword (one definition rule) maybe it doesn't work with the compiler specific inline commands, because they are no c++ keywords?

does anyone know more about this?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#ifdef __GNUG__
     // g++, clang++: [[ gnu::always_inline ]] does not also imply C++ inline
     // [[ gnu::always_inline ]] is an additional implementation-defined
     // attribute using the C++11 unified standard attribute syntax. note: gnu::
     #define FORCEINLINE [[ gnu::always_inline ]] inline

#elif defined _MSC_VER
     // msc++: ____forceinline implies C++ inline
     // msc++ does not provide any additional implementation-defined
     // attributes using the C++11 unified standard attribute syntax
     #define FORCEINLINE __forceinline // inline is implied

#else
     #define FORCEINLINE inline
#endif

struct A
{
   int value() const ;
   void value( int new_value ) ;
   int v = 9 ;
};

FORCEINLINE int A::value() const { return v ; }

FORCEINLINE void A::value( int new_value ) { v = new_value ; }
oh :) thank you!
Topic archived. No new replies allowed.