我試圖使用以下模式。雖然使用#ifndef,.h文件被多次添加
#ifndef TRACER_H
#include "Tracer.h"
#endif
這是聲明被添加到代碼中的每個文件,使tracer.h只添加一次。 仍然我收到一個錯誤說多個對象。
另外Tracer.h包含
#ifndef TRACER_H
#define TRACER_H
以下是錯誤; 我試圖編譯一次,以及:
1>Generating Code...
1>Linking...
1>LINK : \\stu05-fsrv.ad.syr.edu\akbhat$\Visual Studio 2008\Projects\Project3\Debug\Project3.exe not found or not built by the last incremental link; performing full link
1>SemiExpression.obj : error LNK2005: "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class tracer &)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]@@@Z) already defined in main.obj
1>SemiExpression.obj : error LNK2005: "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > tracer::log" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@A) already defined in main.obj
1>Tokenizer.obj : error LNK2005: "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class tracer &)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]@@@Z) already defined in main.obj
1>Tokenizer.obj : error LNK2005: "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > tracer::log" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@A) already defined in main.obj
1>\\stu05-fsrv.ad.syr.edu\akbhat$\Visual Studio 2008\Projects\Project3\Debug\Project3.exe : fatal error LNK1169: one or more multiply defined symbols found
1>Build log was saved at "file://\\stu05-fsrv.ad.syr.edu\akbhat$\Visual Studio 2008\Projects\Project3\Project3\Debug\BuildLog.htm"
請告訴我們該錯誤以及它發生周圍的代碼。 – Thomas 2010-04-18 19:54:37