http://www.drdobbs.com/embedded-systems/225700666をマイクロプロセッサKeil MDK
用に移植していARM
ます。gcc
フレームワークは、デスクトップで使用すると正常にコンパイルおよび動作しますが、Keil
コンパイラを使用するとエラーが発生します。
logging/singleton.h(65): error: #70: incomplete type is not allowed
singleton
次のコードは、このエラーが発生する場所の実装を示しています。このエラーはどこから発生しますか?
namespace logging {
namespace detail {
template <typename T>
class singleton
{
private:
struct obj
{
obj() { singleton<T>::instance(); }
inline void empty() const { }
};
static obj __obj;
singleton();
public:
typedef T obj_type;
static obj_type & instance()
{
static obj_type obj; // <-- Here I get this error
__obj.empty();
return obj;
}
};
template <typename T>
typename singleton<T>::obj
singleton<T>::__obj;
} /* detail */
} /* logging */
編集:singleton
ここでインスタンス化されます
template <typename log_t, typename T>
struct Obj {
static return_type& obj () {
typedef singleton<return_type> log_output;
return log_output::instance();
}
};
return_type
typedefはどこにありますか?
typedef R return_type;
これは親テンプレートのパラメータです。
template<typename Level = ::logging::Void, typename R = loggingReturnType>
class Logger {
...
};
loggingReturnType
クラス定義の上で前方宣言されます:
struct loggingReturnType;
編集2:これloggingReturnType
は次のマクロを通じて生成されます。
#define LOGGING_DEFINE_OUTPUT(BASE) \
namespace logging { \
struct loggingReturnType : public BASE { \
/*! \brief The provided typedef is used for compile time \
* selection of different implementation of the \
* %logging framework. Thus, it is necessary \
* that any output type supports this type \
* definition, why it is defined here. \
*/ \
typedef BASE output_base_type; \
}; \
}
このマクロは、構成ヘッダーで呼び出されます。
編集3:彼女はプリプロセッサ出力へのリンクです:http://www.pasteall.org/31617/cpp。このファイルは、を使用してかなりコンパイルされますg++
。の定義は-loggingReturnType
の前の最後ですmain
。したがって、シングルトンは正確なタイプではありませんが、それでも機能します。Keil
コンパイラのプリプロセッサ出力も調べましたが、ほとんど同じです。
では、ここで何がうまくいかなかったのでしょうか。