2014-12-07 103 views
-1
#include <iostream> 

using namespace std; 

void square (int *); 

int main() { 

    int number = 0; 

    cout << " To find the square of the number entered by the user "; 
    cin >> number; 
    cout << square (&number); 

    return 0; 
} 

void square (int *x) 
{ 
    *x = *x ** x; 
} 
的參考找到平方

誰能告訴什麼是錯誤的代碼,因爲它給我一種大長篇奇怪的錯誤要通過指針

+0

爲什麼不張貼錯誤? – 2014-12-07 07:01:00

+2

:錯誤C2679:二進制'<<':找不到操作符找到類型爲'void'的右側操作數(或者沒有可接受的轉換) – 2014-12-07 07:03:24

+0

請問您能否解釋一下,這是該特定錯誤的簡寫形式 – 2014-12-07 07:03:51

回答

1

由於square不會返回它不能什麼傳遞給cout

相反的值更改線路

cout << square (&number); 

square (&number); 
cout << number; 
+0

爲什麼downvote?care發表評論? – 2014-12-07 07:06:18

+0

@HarisIftikhar - 你的歡迎 – 2014-12-07 07:10:00

1

的錯誤是,main()預計square()return結果,而square是一個void函數,它在原地修改它的參數。

錯誤消息基本上是這樣說的:沒有operator<<需要void,因爲它是右手參數。

+0

downvoter是否會關注評論? – NPE 2014-12-07 07:05:30

+0

我也被拒絕投票了:-(我剛投了票,因爲反對票不公平 – 2014-12-07 07:07:11

+0

這個數字可能是不成熟的僞裝成一種**酸葡萄** downvote。最近幾乎所有種類。 – 2014-12-07 07:30:02