アップデート2をするとき、外部未解決:C +には、Visual Studio 2010の在庫コンパイラを使ってコンパイル:更新こののcppファイルで定義された方法ではなく、ヘッダー内の
を起こし、前方宣言のバグを発見+ 0xが有効になりました。
私は、不思議な動作をしているメンバー関数を持つクラスを持っています。
私がcppファイルでメソッドを定義すると、リンカーは "未解決の外部シンボル"エラーになります。定義をヘッダーに移動すると、コンパイルが正常に行われます。
1)これは私が
任意の考えを困惑)CPPファイルは間違いなく) 3をコンパイルされているテンプレートの方法 2ではないでしょうか?
ヘッダファイル
// THIS IS THE ERROR HERE: I forward declare TPA as a class, when it is actually a struct
class TollingPathAttributes; // forward declare the TollingPathAttributes struct as a class (doh!)
class TollingPathAttributesOutput
{
public:
TollingPathAttributesOutput(HighwayCommand* command);
~TollingPathAttributesOutput();
void foo();
void AddPathAttributes(boost::shared_ptr<TollingPathAttributes> attributes);
protected:
string m_outputFilename;
vector<shared_ptr<TollingPathAttributes>> m_data;
queuing_mutex m_dataMutex;
};
CPPファイル
void TollingPathAttributesOutput::foo() {}
void TollingPathAttributesOutput::AddPathAttributes(boost::shared_ptr<TollingPathAttributes> attributes)
{
queuing_mutex::scoped_lock lock(m_dataMutex);
m_data.push_back(attributes);
}
呼び出しコール
m_output->foo(); // compiles and links no problem
boost::shared_ptr<TollingPathAttributes> attr =
boost::make_shared<TollingPathAttributes>(origin, dest, UNTOLLED_OPTION, vector<int>(), 0.0, 0.0);
m_output->AddPathAttributes(attr); // compiles fine, but only links correctly if I move the definition to the header
リンクエラー
1>OtCustomZenith_logic.lib(TollingPathAttributesRecorder.obj) : error LNK2019: unresolved external symbol "public: void __thiscall TollingPathAttributesOutput::AddPathAttributes(class boost::shared_ptr<class TollingPathAttributes>)" ([email protected]@@[email protected]@@@[email protected]@@Z) referenced in function "public: virtual void __thiscall TollingPathAttributesRecorder::Record(class TolledPath &,class boost::shared_ptr<class Path>,int)" ([email protected]@@[email protected]@[email protected]@@@[email protected]@[email protected])
1>..\..\..\OT\OtCustomZenith_test.exe : fatal error LNK1120: 1 unresolved externals
どのようにコンパイルしていますか? –
私の正常なデバイスではありません。私はテストすることができないので、これは単なる誤植かもしれませんが、m_dataはshared_ptrのベクトルです(名前空間としてのboostではなく)。他の参照には名前空間があります。 – tmpearce
@tmpearce明示的なboost :: shared_ptrは、メソッドのcall site/header/cpp定義間の不一致を排除することでした。私は一般的にboost :: shared_ptrをどこかで使用しています。私はshared_ptrがboost名前空間から来ていると確信しています。 –