Reputation: 13575
For example
// a.h
strcut A
{
void simpleMethod();
void anotherMethod() {...; simpleMethod(); ...;}
};
// a.cpp
#include "a.h"
void A::simpleMethod() { one_line_simple_implementation; }
My question is: Can simpleMethod()
be inlined in anotherMethod()
by the modern compiler optimization?
Upvotes: 0
Views: 41
Reputation: 104
you can use inline void A::simpleMethod() { ... }
or you might get multiple definitions error if you don't use inline
keyword.
or you could just do
class A
{
void foo() { ... };
};
Upvotes: 0
Reputation: 11047
In this case, yes. if a.cpp
includes a.h
(I suppose so). As long as the compiler can see the full definition. it is fine. But you need to say so.
inline void A::simpleMethod() { one_line_simple_implementation; }
Upvotes: 1