c++11 - C++ implicit conversion does not work -


been trying c++11 g++ 5.3.1 while... thought understood implicit conversion operators. speaking, if define class3::operator class2() can pass class3 directly function takes class2. seems work 99% of time... have encountered simple example not case.

class class1 {};  class class2 { public:   inline friend class1 & operator<<(class1 & a, class2 const& c)   {return a;} };  class class3 { public:   inline operator class2() const {return class2();} };  void foo(class2 c) {}  int main() {   class1 c1;   class3 c3;    // g++ not this:   // error: no match 'operator<<' (operand types 'class1' , 'class3')   // c1 << c3;    // g++ likes these fine:   foo(c3);   c1 << class2(c3); } 

any ideas did wrong? please help! thanks.

friend functions defined inside class definition, without out-of-class declaration, visible argument-dependent lookup, , if class defined in associated class of 1 of arguments.

class2 not associated class of class1 or class3, , operator<< isn't declared out-of-class, not found name lookup c1 << c3. without knowing such operator<< exists, implicit conversion doesn't come play.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -