私はインターネットで C++ のインライン化について多くのことを検索しましたが、誰もが別の実装方法を好むようです。
私の問題は次のようになります。
// header-file
class Test {
int i;
public:
int getI();
};
// source-file
int Test::getI() { return i; }
この関数getI()
は数千回呼び出されるため、この関数を「インライン化」すると便利だと思います。そうする最善の方法は何ですか:
// 1) define the function within the class-definition
class Test {
int i;
public:
int getI() { return i; }
};
// 2) define the function within the header-file
inline int Test::getI() { return i; } // directly located under class-definition
// 3) let the fct-definition stay in the source file and write "inline" before it (somehow this does not compile)
どの方法が最良または最もパフォーマンスの高い実装であるかのヒントを教えてください。手伝ってくれてありがとう :)