諸如這樣的問題
http://social.msdn.microsoft.com/Forums/ar-SA/vcgeneral/thread/a4490504-956f-44d0-a39c-3a4bd36a4aac
I have the following lines
of code in my header file of a C++ CLR application:
#include<cliext/vector>
using namespace cliext;
...
vector <String^>^ availVector;
I then have the following lines of code in my CPP file in a method :
availVector = gcnew vector<String^>();
availVectsr->push_pack("test");
when I tried to compile the program I get the following linker errors:
1>CommandFile.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: cliext.impl.vector_impl<System::String ^,0>; fields: _Myarray): (0x04000029).
在我的項目裡也出現了.找不到切實可行的解決辦法,最後想到一招注意,完美的解決了這個問題:
把所有使用
cliext::vector<MyClass^>
的地方替換成
MyClassVector;
然後
ref struct MyClassVector : public cliext::vector<MyClass^>{};
這樣就能避免LNK2022錯誤了.
發生錯誤的時候的代碼是
typedef cliext::vector<MyClass^> MyClassVector;
這是我想到的辦法,另外還有一種解決辦法,是從網路上搜尋到的
template ref class cliext::vector<MyClass^>;
typedef cliext::vector<MyClass^> item_unit_vectory;
主要將
template ref class cliext::vector<MyClass^>;
放在所有的代碼最前面(一般我放先行編譯標頭檔裡)就好