的模板,所以我有代表說,自定義集合如下模板:C++構造模板
template <typename T> class MyCollection {
private:
std::vector<T> v;
public:
MyCollection(int n) {
v.resize(n);
}
etc
}
但是現在,我要實例MyCollection的對象MyCollection的,所以我做這在我的主程序:
MyCollection<MyCollection<int>> mycoll= MyCollection<MyCollection<int>>(100);
這確實會編譯(我的MAC,使用以下):
clang++ -std=c++11 -stdlib=libc++ test.cpp
問題是我得到這樣一個鏈接器錯誤:
Undefined symbols for architecture x86_64:
"std::__1::__vector_base_common<(unsigned char)1>::__throw_length_error() const", referenced from:
std::__1::vector<MyCollection<int>, std::__1::allocator<MyCollection<int> > >::allocate(unsigned long) in test-891fb4.o
這究竟是什麼,我該如何解決它?它看起來像一個關於vector>的分配器丟失了嗎?爲什麼會發生這種情況,我該如何解決?
默認的C++運行時是GNU實現,並在使用libC++編譯時混淆鏈接器。 –
那麼我該如何解決這個問題? – Marc
你試過了嗎?clang ++ -std = C++ 11 -stdlib = libC++ test.cpp -lsupC++'? libsupC++定義了異常 – Praetorian