warning C4552: '' : operator has no effect; expected operator with side-effect
生活随笔
收集整理的這篇文章主要介紹了
warning C4552: '' : operator has no effect; expected operator with side-effect
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1》編寫一個自定義的函數shift_right:利用引用形參實現對一個int型的數據右移n位。
代碼如下:
#include<iostream> using namespace std; void shift_right(int &num,int n); int main(){int num=8;cout<<"before shift ,num:"<<num<<endl;shift_right(num,2);cout<<"after shift ,num:"<<num<<endl;return 0; }void shift_right(int &num,int n){num>>n; }運行結果如下:
為什么 沒有實現右移的功能呢?
看編譯的提示:warning C4552: '>>' : operator has no effect; expected operator with side-effect
大致意思是:操作符“>>”未產生任何影響;期望使用能產生side-effect的操作符。
2》將上述shift_right函數做如下更改:
void shift_right(int &num,int n){num>>=n; }即將“>>”更改為“>>=”.
再次運行該程序,結果如下:
可以發現,結果正常了,warning也沒有了。
ps:warning有時候也是不可忽視的。
總結
以上是生活随笔為你收集整理的warning C4552: '' : operator has no effect; expected operator with side-effect的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mac android studio升级
- 下一篇: Convolutional Neuron