user1899020
user1899020

Reputation: 13575

Can the method defined in source file be inlined?

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

Answers (2)

Max
Max

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

CS Pei
CS Pei

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

Related Questions