Considering next simple example:
The header:
// a.hpp
#ifndef A_HPP
#define A_HPP
#include <memory>
class A
{
public:
A();
int foo();
private:
struct Imp;
std::auto_ptr< Imp > pimpl;
};
#endif // A_HPP
The implementation :
// a.cpp
#include "a.hpp"
struct A::Imp
{
int foo()
{
// do something and return the result
}
};
A::A() : pimpl( new Imp )
{}
int A::foo()
{
return pimpl->foo();
}
The main :
// main.cpp
#include "header.hpp"
int main()
{
A a;
return a.foo();
}
The questions are :
Is the method A::Imp::foo
going to get inlined into A::foo
?
Does it depend on the implementation what is in that method?
PS I am using gcc (4.3.0 if it matters).
EDIT
I guess I didn't explain very well. What I exactly meant is this. If I use the maximum optimization level, is the // do something and return the result
going to be placed in the A::foo()
or A::Imp::foo()
?
Without optimization, I see that this is not done (the pimpl->foo()
is still called).
I understand that A::foo() will never get inlined in main(), but that is not what I am asking.