2011-05-05 59 views
0

我想使用對象接受一個十六進制值到鏈接列表中,並允許用戶添加/乘以列表中的值的基本C++程序。問題是我在我的對象的乘法區域遇到編譯器錯誤。下面的代碼:鏈接列表不匹配運算符*編譯器錯誤

void LList::Multi() { 
    element new_input; 
    element temp; 
    element temp1; 
    cout << "Please enter the number you would like to multiply." <<endl; 
    new_input = Read_Element(); 
    temp = head −> data; 
    temp1 = (temp * new_input); 
    head −> data = temp1; 
} 

這裏是我得到的錯誤: LList.cpp:在成員函數void LLIST ::多():LList.cpp:77:錯誤:不對應的運營商*在臨時* new_input

我只使用了<的iostream> < stdlib.h>中和<字符串>庫,任何投入將非常感謝。

+0

你好,@ deadly.foxie。歡迎來到堆棧溢出!什麼是元素? – 2011-05-05 22:00:11

回答

2

如果要在element類型的對象上使用*運算符,則需要重載該運算符。你得到的錯誤是告訴你,你還沒有寫過一個可以在兩個對象上使用的操作符重載函數。

+0

感謝您的回覆,我意識到我做錯了什麼。愚蠢的是我試圖增加蜇傷。 – 2011-05-05 22:52:46