2016-06-01 4 views
1

私はクラスExecuterExecuter.hppExecuter.cppに分割して定義しました。 Executer.hppC++ - Eclipse - Organize include

コードがある:

static std::unique_ptr<Executer> mInstance; 
static std::once_flag mOnceFlag; 

Executer.cppでコードがあります:

std::unique_ptr<Executer> Executer::mInstance; 
std::once_flag Executer::mOnceFlag; // without this apparently 
    // useless line of code, the program using this shared lib 
    // claims: undefined reference to `Executer::mOnceFlag' 

その後、私は日食私の輸入を整理できるようにしてみてください。

私は何を得ることである:私は何を期待

//------------------------------- Executer.hpp 
#include <memory> 
#include <stdexcept> 
#include <string> 

namespace std { 
struct once_flag; 
} /* namespace std */ 
//------------------------------- Executer.cpp 
#include "Executer.hpp"  
#include <mutex> 

(とも正しくコンパイルされている):

//------------------------------- Executer.hpp 
#include <memory> 
#include <mutex> 
#include <stdexcept> 
#include <string> 
//------------------------------- Executer.cpp  
#include "Executer.hpp"  
  1. Eclipseはそのように動作しているのはなぜ?
  2. 私は(私は多くのオプションを見てきましたが、私は最悪のものだ)が含ま整理の私の方法を得るようにEclipseを設定でき

答えて

0

Eclipseはその中で動作しているのはなぜ方法?

静的データメンバーのタイプは、データメンバーの宣言時点で完了する必要はありません。つまり、宣言は定義されていない、前方宣言された型でコンパイルされます。

"Organize Includes"のデフォルト設定では、他のヘッダーに含まれるヘッダーの数を最小限に抑えて、コンパイル時間を短縮します。したがって、型の前方宣言が十分であれば、タイプを定義するヘッダーを含めること。 Preferences | C/C++ | Code Style | Organize IncludesForward declare classes, structs and unionsのチェックを外す

私は(私は多くのオプションを見てきましたが、私は最悪のものだ)が含ま整理の私の方法を取得するようにEclipseを設定でき

はあなたを与える必要がありますあなたが望む行動。