2012-02-12 93 views
-1
enter code here 

我使用dev C++進行編程。因爲我正在使用一些在開發C++上開發的庫,我想使用相同的編譯器。任何想法解決「鏈接器錯誤」undefiend參考

對於我自己的開發項目,我想要一些新的類。所以我已經添加了2個類"TriangleLists, TriangleList"(h文件和cpp文件)到庫中。當我編譯庫時,它沒有任何錯誤,並能夠創建新的庫文件。但是,當我編譯我自己的項目時,我得到了鏈接器錯誤問題。

[Linker error] undefined reference to `TriangleLists::Erase()' 
[Linker error] undefined reference to `TriangleList::TriangleList(TriangleList const&)' 
[Linker error] undefined reference to `TriangleList::operator=(TriangleList const&)' 
ld returned 1 exit status 

實際上,在庫中有相似的類叫RectangleList, RectangleLists ..所以,我複製的2類和修改,以適應我的TriangleList類。

有什麼建議可以解決這個問題。在此先感謝,

+1

您是否已將包含這些實現的源文件添加到構建中? – 2012-02-12 18:02:51

+0

你正在使用哪一本C++書? – 2012-02-12 18:03:11

+0

這個問題很難回答。你已經描述了*發生了什麼*,但不是你*做了什麼*。請說明你做了什麼。 – 2012-02-12 18:03:22

回答

0

TriangleLists是由您製作的還是屬於圖書館?

通常一個類對象不打算被複制,只是不能完成。爲防止庫用戶複製不可複製對象,創建者可以聲明覆制構造函數和賦值運算符(通常爲私有),但省略定義。如果是這種情況,那麼不要複製對象,也不要以涉及複製的方式使用它們(比如將它們放在一些容器中)。你可能在堆上創建對象並將指向這些對象的指針指向一個容器。

編輯:如果那些是你的課,那麼答案很簡單。將函數Erase添加到類TriangleLists,並將複製構造函數和賦值運算符添加到類TriangleList。由於您正在從類似的類複製功能RectangleList搜索其複製構造函數和賦值運算符RectangleList::RectangleList(RectangleList const&)RectangleList::operator=(RectangleList const&)

+0

我不確定,因爲我的C++基礎知識非常低,所以我沒有正確地使用它。 (無論如何,是的,TriangleLists和TriangleList是我添加到lib中的新類)。實際上,在庫中有類似的類,稱爲RectangleList,RectangleLists ..所以,我以同樣的方式修改了函數到TriangleList類...可能是如果你說簡單的方法做什麼,那麼它真的很有幫助。謝謝 – gnp 2012-02-12 18:21:19

+0

好的,我編輯了答案。 – Dialecticus 2012-02-12 18:28:58