c++ - const reference syntax difference between visual studio and gcc -


#include <iostream>  void swap(float& const a, float& const b) {}  int main() {     std::cout << "hello, world!\n"; } 

this simple code compiles in visual studio (vs2013) not in gcc. have tried c++ 10 , c++11. gcc gives error saying

error: 'const' qualifiers cannot applied 'float&'

but if change function definition

void swap(float const &a, float const &b) 

it compiles in gcc , visual studio.

my question is, both these syntaxes mean same thing? also, why compiles visual studio , not gcc

float& const a invalid. reference cannot const. can refer const object cannot const (it meaningless since it's not reseatable).

c++14 §8.3.2/1:

cv-qualified references ill-formed except when cv-qualifiers introduced through use of typedef-name (7.1.3, 14.1) or decltype-specifier (7.1.6.2), in case cv-qualifiers ignored.

a decltype-specifier use of decltype keyword.


visual c++ 2015 warn (at warning level 4):

 c:\my\forums\so\141> cl foo.cpp /feb foo.cpp foo.cpp(3): warning c4227: anachronism used: qualifiers on reference ignored foo.cpp(3): warning c4100: 'b': unreferenced formal parameter foo.cpp(3): warning c4100: 'a': unreferenced formal parameter  c:\my\forums\so\141> g++ foo.cpp -wno-unused-parameter foo.cpp:3:24: error: 'const' qualifiers cannot applied 'float&'  void swap(float& const a, float& const b)                         ^ foo.cpp:3:40: error: 'const' qualifiers cannot applied 'float&'  void swap(float& const a, float& const b)                                         ^  c:\my\forums\so\141> _ 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -