c++ - What does 'const' do when used in a pointer to pointer rvalue const function argument? -


void func(int **&&const x)  {        *(*x) = 32;   }  void main() {     int *pi = new int{ 64 };      printf("x : %d\n", *pi);      func(&pi);      printf("x : %d\n", *pi); }   outputs:  x : 64  x : 32  

when using pointer pointer rvalue const, value still modifiable within function. there purpose using **&&const function argument. code compiled using vc2013 c++ compiler nov 2013.

edit: receive warning "anachronism used : qualifiers on reference ignored" it's better fail compile completely. answers!

gcc 4.8.2 doesn't consider valid code:

// snippet of code void func(int **&& const x) {     *(*x) = 32;  } 

... , compile ...

$ g++ -fsyntax-only -wall -pedantic -std=c++11 foo.cpp foo.cpp:2:26: error: ‘const’ qualifiers cannot applied ‘int**&&’  void func(int **&& const x)                           ^ 

i'm going assume vc 2013 wrong allow code compile.


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -