Are the methods in pimpl inlined?

Given the following simple example:

Title:

// 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

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();
}

Main:

// main.cpp
#include "header.hpp"
int main()
{
  A a;
  return a.foo();
}

Questions:
Is the method able to A::Imp::fooget in A::foo?
Does it depend on the implementation of what is in this method?

PS I am using gcc (4.3.0 if that matters).

EDIT

I think I didn’t explain very well. That I meant just that. If I use the maximum level of optimization, will it be // do something and return the resultplaced in A::foo()or A::Imp::foo()?
Without optimization, I see that this is not done ( the pimpl->foo()still being called).

I understand that A :: foo () will never go into main (), but that is not what I am asking for.

+3
source share
2 answers

.

: inlining?

++:

  • (LTO: )

: / , / , . , , , , .

, .

  • : ,
  • : , , , ... afaik, , DLL

, : , pimpl->foo() A::foo. , .

gcc/clang, A::Impl::foo , O1 ( -fno-inline).

+7

. , .

+9

All Articles