Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Templates & automatic type conversion
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Szabolcs, post: 2924062"] Consider the attached example. When I try to compile it (with g++ 4.1.2), I get the error message error: no matching function for call to 'fun(A<int>&)' However, if I do not use templates, it compiles without errors. Could someone please explain why this happens? Is there a workaround? ------------->8--------------- // With A and B templates template<typename T> struct B { }; template<typename T> struct A { operator B<T> () { return B<T>(); } }; template<typename T> void fun(B<T> b) { } int main() { A<int> a; fun(a); return 0; } ------------->8--------------- // Without templates struct B { }; struct A { operator B() { return B(); } }; void fun(B b) { } int main() { A a; fun(a); return 0; } [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Templates & automatic type conversion
Top