c++ - A CV-qualified type cannot be converted to the cv-unqualified type -


i've written example:

#include <iostream>  struct {     a(const a&){ std::cout << "a(const a&)" << std::endl; }     a(){ std::cout << "a()" << std::endl; } };  struct b {     b(){ std::cout << "b()" << std::endl; }     operator a(){ std::cout << "operator a()" << std::endl; return a(); } };  b b;  void foo(a) { }  int main(){ std::cout << "main function starting..." << std::endl; foo(b); } 

demo

it works fine, if replace b b; const b b; won't work.

#include <iostream>  struct {     a(const a&){ std::cout << "a(const a&)" << std::endl; }     a(){ std::cout << "a()" << std::endl; } };  struct b {     b(){ std::cout << "b()" << std::endl; }     operator a(){ std::cout << "operator a()" << std::endl; return a(); } };  const b b;  void foo(a) { }  int main(){ std::cout << "main function starting..." << std::endl; foo(b); } 

demo

although standard says in section 13.3.3.1/6 [over.best.ics]:

any difference in top-level cv-qualification subsumed initialization , not constitute conversion.

i wish explain me why seond example doesn't work.

the line quoted under section titled 13.3.3.1.1 standard conversion sequences. conversion b a user defined conversion. rules user defined conversions under next section of standard , titled 13.3.3.1.2 user-defined conversion sequences

what quoted not apply user defined conversions.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -