考虑下一个简单的例子:
标题:
// 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
实施:
// 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.cpp
#include "header.hpp"
int main()
{
A a;
return a.foo();
}
问题是:
该方法A::Imp::foo
会被内联到A::foo
吗?
它是否取决于该方法中的实现?
PS我正在使用gcc(如果重要的话是4.3.0)。
编辑
我想我解释得不是很好。我的真正意思是这个。如果我使用最大优化级别,是// do something and return the result
要放在A::foo()
or中A::Imp::foo()
吗?
没有优化,我看到这还没有完成(the pimpl->foo()
仍然被调用)。
我知道 A::foo() 永远不会在 main() 中内联,但这不是我要问的。