c++11 - auto with const_cast reference behaves strange -


can me understand "weird" behavior? playing around c++11 after long pause in c++ programming. why works fine until use auto?

static void printit(int a,const int *b, const int &c) {      std::cout << "\narg1 : " << << "\narg2 : " << *b << "\narg3 : " << c       << std::endl; }  int main() {     int myvar { 0x01 };     const int *pmv { &myvar };     const int &rmv { myvar };      printit(myvar,pmv,rmv); //ok prints 1,1,1      *(const_cast<int *>(pmv)) = 0x02;   //remove constness pmv , sets new value     printit(myvar,pmv,rmv); //ok prints 2,2,2      (const_cast<int &>(rmv)) = 0x03;    //remove constness rmv , sets new value     printit(myvar,pmv,rmv); //ok prints 3,3,3      myvar = 0x04;     printit(myvar,pmv,rmv); //ok prints 4,4,4      //so far good...      auto = const_cast<int *>(pmv);    //creates new variable of type int *     *a = 0x05;     printit(myvar,a,rmv); //ok prints 5,5,5      auto b = const_cast<int &>(rmv);    //should have same effect (const_cast<int &>(rmv)), right???     b = 0x06;     printit(myvar,a,b); //wrong!!! prints 5,5,6 } 

can me? much.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -