What are some C++ related idioms, misconceptions, and gotchas that you've learnt from experience?

前端 未结 16 2137
刺人心
刺人心 2021-01-29 19:48

What are some C++ related idioms, misconceptions, and gotchas that you\'ve learnt from experience?

An example:

class A
{
  public: 
  char s[1024];
  cha         


        
16条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-29 20:06

    Nothing I actually came across while programming, but a friend wanted an explanation on why the code worked. It took me a while to figure it out. Maybe it is obvious to you guys, but I am not an experienced programmer.

    #include 
    using namespace std;
    
    int& strangeFunction(int& x){return x;}
    
    
    int main(){
            int a=0;
            strangeFunction(a) = 5;               //<------- I found this very confusing
            cout << a <

提交回复
热议问题