#include <iostream> struct B; struct A{ operator B(); }; struct B{ B(A &) { std::cout << "conversion constructor" << std::endl; }}; A::operator B() { std::cout << "conversion operator" << std::endl; } int main() { A a; B b = a; return 0;}
Standard input is empty
prog.cpp: In function ‘int main()’: prog.cpp:20: error: conversion from ‘A’ to ‘B’ is ambiguous prog.cpp:15: note: candidates are: A::operator B() prog.cpp:12: note: B::B(A&)
Standard output is empty
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!