我看到鏈接器錯誤,所以需要你的幫助。 我有一個名爲DBFieldBase的類的X.dll。在我的工作區X中,我正在使用矢量來處理一些數據庫相關的應用程序。我正在使用的矢量來自第三方ospace。 現在我正嘗試在另一個工作空間Y中使用矢量。我在Visual Studio 2010的鏈接器 - >輸入選項中添加了相應的包含文件和.lib文件。 我爲工作空間X做了dllexport並在Y中使用它使用dllimport。 這我得到如下得到一個鏈接器錯誤,因爲已經定義了運算符
X.lib(X.dll)給出的錯誤:錯誤LNK2005: 「市民:類DBFieldBase * & __thiscall矢量::運算符[](unsigned int類型)」(? ??A $ @載體@@@@ PAVDBFieldBase @@ QAEAAPAVDBFieldBase我@ Z)已經 在sdb.obj
我不知道到底是什麼原因造成這個錯誤定義。相同的代碼在VS 6.0中成功編譯,現在我試圖在VS2010中構建它。請讓我知道我是否缺少任何東西。 在此先感謝。
P.S.我試圖在互聯網上搜索解決方案的類似問題,但不幸的是沒有成功。
爲矢量代碼是從第三方在下面給出:
class os_vector
{
public:
typedef T value_type;
typedef OS_REFERENCE(T) reference;
typedef OS_CONST_REFERENCE(T) const_reference;
typedef OS_SIZE_TYPE(T) size_type;
typedef OS_DIFF_TYPE(T) difference_type;
typedef OS_ALLOCATOR(T) allocator_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T* iterator;
typedef const T* const_iterator;
typedef os_reverse_iterator
<
T*,
T,
OS_REFERENCE(T),
T*,
OS_DIFF_TYPE(T)
> reverse_iterator;
typedef os_reverse_iterator
<
const T*,
T,
OS_CONST_REFERENCE(T),
const T*,
OS_DIFF_TYPE(T)
> const_reverse_iterator;
// Construct me to be an empty vector.
os_vector() :
start_(0),
finish_(0),
end_of_storage_(0),
alloc_()
{
}
// Construct me to be an empty vector.
explicit os_vector(const OS_ALLOCATOR(T) & alloc) :
start_(0),
finish_(0),
end_of_storage_(0),
alloc_(alloc)
{
}
// Construct me to contain `n` (>0) elements. Each element will be
// a copy of `value`.
os_vector
(
size_type n,
const T& value, // = T()
const OS_ALLOCATOR(T) & alloc // = OS_ALLOCATOR(T)()
) :
start_(0),
finish_(0),
end_of_storage_(0),
alloc_(alloc)
{
assign(n, value);
}
os_vector (size_type n, const T& value) :
start_(0),
finish_(0),
end_of_storage_(0),
alloc_()
{
assign(n, value);
}
os_vector (size_type n) :
start_(0),
finish_(0),
end_of_storage_(0),
alloc_()
{
assign(n, T());
}
// Construct me to contain copies of all the elements in `original`.
os_vector(const os_vector OS_ALLOCATE_ARG_2(T, Allocator) & original) :
start_(0),
finish_(0),
end_of_storage_(0),
alloc_(original.get_allocator())
{
assign(original.begin(), original.end());
}
// Construct me to contain all of the elements in the
// range [`first`, `last`).
template< class InIt >
os_vector
(
InIt first,
InIt last,
const OS_ALLOCATOR(T) & alloc = OS_ALLOCATOR(T)()
) :
start_(0),
finish_(0),
end_of_storage_(0),
alloc_(alloc)
{
assign(first, last);
}
// Destroy me.
~os_vector()
{
clear();
}
// Replace my contents with a copy of the elements in `original`,
// resizing if necessary.
os_vector OS_ALLOCATE_ARG_2(T, Allocator) & operator=
(
const os_vector OS_ALLOCATE_ARG_2(T, Allocator) & original
);
// Remove all my current elements, and then insert the elements
// in range [`first`, `last`).
void assign(const_iterator first, const_iterator last)
{
if (first == begin())
erase(begin() + (last - first), end());
else
assign_aux(first, last);
}
// Remove all my current elements, and then insert the elements
// in range [`first`, `last`).
template< class InIt >
void assign(InIt first, InIt last)
{
assign_aux(first, last);
}
// Remove all my current elements, and then insert `n` copies of
// `value`.
void assign(size_type n, const T& value);
void assign(size_type n)
{
assign(n, T());
}
// Return a copy of the allocator I am using.
allocator_type get_allocator() const
{
return alloc_;
}
// Return a random access iterator positioned at my first element.
iterator begin()
{
return start_;
}
// Return a constant random access iterator positioned at my first
// element.
const_iterator begin() const
{
return start_;
}
// Return a random access iterator positioned immediately after my
// last element.
iterator end()
{
return finish_;
}
// Return a constant random access iterator positioned immediately after
// my last element.
const_iterator end() const
{
return finish_;
}
// Return a random access reverse iterator positioned immediately after
// my last element.
reverse_iterator rbegin()
{
return reverse_iterator(end());
}
// Return a constant random access reverse iterator positioned
// immediately after my last element.
const_reverse_iterator rbegin() const
{
return const_reverse_iterator(end());
}
// Return a random access reverse iterator positioned at my first
// element.
reverse_iterator rend()
{
return reverse_iterator(begin());
}
// Return a constant random access reverse iterator positioned at my
// first element.
const_reverse_iterator rend() const
{
return const_reverse_iterator(begin());
}
// Return the number of elements that I contain.
size_type size() const
{
return end() - begin();
}
// Return the maximum number of elements that I can contain.
size_type max_size() const
{
return alloc_.max_size();
}
// Cause myself to hold `n` elements, using `value` to expand
// myself if necessary.
void resize(size_type n, T value)
{
if (n > size())
insert(end(), n - size(), value);
else
erase(begin() + n, end());
}
// Cause myself to hold `n` elements using the default constructor
// to expand myself if necessary.
void resize(size_type n)
{
resize(n, T());
}
// Return the number of elements that I can contain without allocating
// more memory.
size_type capacity() const
{
return end_of_storage_ - start_;
}
// Return true if I contain no elements.
bool empty() const
{
return begin() == end();
}
// Change my capacity to be at least `n`. Does not affect my
// current size.
void reserve(size_type n);
// Return a reference to my `n`th element.
reference operator[](size_type n)
{
OS_ASSERT_NOT_EMPTY(empty())
OS_ASSERT_INDEX_OK(n, 0, size() - 1)
return *(begin() + n);
}
// Return a constant reference to my `n`th element.
const_reference operator[](size_type n) const
{
OS_ASSERT_NOT_EMPTY(empty())
OS_ASSERT_INDEX_OK(n, 0, size() - 1)
return *(begin() + n);
}
// Return a reference to my `n`th element.
reference at(size_type n)
{
if (n >= size())
os_throw_out_of_range();
return *(begin() + n);
}
// Return a constant reference to my `n`th element.
const_reference at(size_type n) const
{
if (n >= size())
os_throw_out_of_range();
return *(begin() + n);
}
// Return a reference to my first element.
reference front()
{
OS_ASSERT_NOT_EMPTY(empty())
return *begin();
}
// Return a constant reference to my first element.
const_reference front() const
{
OS_ASSERT_NOT_EMPTY(empty())
return *begin();
}
// Return a reference to my last element.
reference back()
{
OS_ASSERT_NOT_EMPTY(empty())
return *(end() - 1);
}
// Return a constant reference to my last element.
const_reference back() const
{
OS_ASSERT_NOT_EMPTY(empty())
return *(end() - 1);
}
// Add `value` at my end.
void push_back(const_reference value)
{
if (finish_ != end_of_storage_)
{
alloc_.construct(finish_, value);
++finish_;
}
else
insert_aux(end(), value);
}
// Erase my last element.
void pop_back()
{
OS_ASSERT_NOT_EMPTY_ELSE(empty())
{
--finish_; // not on a single line due to Borland problem
alloc_.destroy(finish_);
}
}
// Insert `value` at `pos` and return an iterator pointing to the new
// element's position.
iterator insert(iterator pos, const T& value)
{
size_type n = pos - begin();
if (finish_ != end_of_storage_ && pos == finish_)
{
alloc_.construct(finish_, value);
++finish_;
}
else
insert_aux(pos, value);
return begin() + n;
}
// Insert an element constructed with the default constructor at `pos` and
// return an iterator pointing to the new element's position.
// not standard, left for backward compatibility
iterator insert(iterator pos)
{
return insert(pos, T());
}
// Insert `n` copies of `value` at `pos`.
void insert(iterator pos, size_type n, const T& value);
// Insert copies of the elements in range [`first`, `last`) at `pos`.
template< class InIt >
void insert(iterator pos, InIt first, InIt last);
// Erase the element at `pos`.
iterator erase(iterator pos)
{
if (!(pos + 1 == end()))
copy(pos + 1, end(), pos);
pop_back();
return pos;
}
// Erase the elements in range [`first`, `last`).
iterator erase(iterator first, iterator last)
{
iterator i = copy(last, end(), first);
destroy(i, finish_, alloc_);
finish_ = finish_ - (last - first);
return first;
}
// Swap my contents with those of `original`.
void swap(os_vector OS_ALLOCATE_ARG_2(T, Allocator) & original)
{
if (!(alloc_ == original.alloc_))
{
os_vector OS_ALLOCATE_ARG_2(T, Allocator) tmp(*this);
assign(original.begin(), original.end());
original.assign(tmp.begin(), tmp.end());
}
else
{
::swap(start_, original.start_);
::swap(finish_, original.finish_);
::swap(end_of_storage_, original.end_of_storage_);
::swap(alloc_, original.alloc_);
}
}
// Erase all of my elements.
void clear()
{
if (start_)
{
destroy(start_, finish_, alloc_);
alloc_.deallocate(start_);
}
start_ = finish_ = end_of_storage_ = 0;
}
protected:
void insert_aux(T* pos, const T& value);
template< class InIt >
void assign_aux(InIt first, InIt last);
private:
// Data members.
iterator start_;
iterator finish_;
iterator end_of_storage_;
allocator_type alloc_;
public:
// Construct me to contain n (>0) elements. Each element will be
// default constructed.
// This remains for compatibility. It will be removed in a future release.
os_vector
(
const OS_ALLOCATOR(T) & alloc,
size_type n
) :
start_(0),
finish_(0),
end_of_storage_(0),
alloc_(alloc)
{
assign(n, T());
}
// Construct me to contain n (>0) elements. Each element will be
// a copy of `value`.
// This remains for compatibility. It will be removed in a future release.
os_vector
(
const OS_ALLOCATOR(T) & alloc,
size_type n,
const T& value
) :
start_(0),
finish_(0),
end_of_storage_(0),
alloc_(alloc)
{
assign(n, value);
}
// Construct me to contain copies of all the elements in `original`.
// This remains for compatibility. It will be removed in a future release.
os_vector
(
const OS_ALLOCATOR(T) & alloc,
const os_vector OS_ALLOCATE_ARG_2(T, Allocator) & original
) :
start_(0),
finish_(0),
end_of_storage_(0),
alloc_(alloc)
{
assign(original.begin(), original.end());
}
// Construct me to contain all of the elements in the
// range [`first`, `last`).
// This remains for compatibility. It will be removed in a future release.
os_vector
(
const OS_ALLOCATOR(T) & alloc,
const_iterator first,
const_iterator last
) :
start_(0),
finish_(0),
end_of_storage_(0),
alloc_(alloc)
{
assign(first, last);
}
// Erase all of my elements.
// This remains for compatibility. It will be removed in a future release.
void erase()
{
clear();
}
};
在X.DLL我有一個類DBFieldBase其像我們我們與成員變量和函數正常類。
Y中的工作區在我使用矢量類的使用在下面給出的一個:
private:
vector < DBFieldBase *> & GetASDVect (void);
vector <DBFieldBase *> m_ASDVect;
然後在外面相同的頭文件類有定義GetASDVect。它的內聯
inline vector <DBFieldBase *> & ASD_sdb::GetASDVect (void)
{
return this->m_ASDVect;
}
讓我知道你是否需要我身邊的其他東西。
你可以發表相關類型的標題代碼嗎?像「內聯」的Smeels在某個地方被遺忘了。並且確保不要使用VS 6.0中的任何庫代碼,編譯器/庫在發佈時已經過時,實際上它是我嘗試過的最差的編譯器,而且我浪費了很多年,因爲我是一個不瞭解更好的新手。 – 2012-03-13 13:19:36
你想要的是哪個頭文件代碼。你想要一個DBFieldBase類的代碼或第三方向量定義存在的文件或工作空間Y中的頭文件,我在這裏使用向量對不起,我不確定你究竟問了什麼,所以要求重新提問 –
novice
2012-03-13 13:26:37
也許開始於第三方vector :: operator []的代碼。我的猜測是它是在課外定義的,但是在標題中,沒有'inline'。 – 2012-03-13 13:34:00