X*r
4 楼
In case of a function template, template argument deduction is performed
before the compiler tries to resolve the overloading [13.3.1 paragraph 7].
In other words, the compiler sees "a*b", then it looks for all overloaded "
operator*". You have "template operator *(const A&, const A&)
;" defined up there, so it tries to deduct the typename T. Note that the
compiler doesn't look into anything else in this step, including your user-
defined conversion function. Obviously it cannot f
before the compiler tries to resolve the overloading [13.3.1 paragraph 7].
In other words, the compiler sees "a*b", then it looks for all overloaded "
operator*". You have "template
;" defined up there, so it tries to deduct the typename T. Note that the
compiler doesn't look into anything else in this step, including your user-
defined conversion function. Obviously it cannot f
h*o
6 楼
谢谢,我明白这层意思了
之所以我想用implicit conversion,就是因为class A已经有很多运算了
一个一个再重写既麻烦,我又不知道是不是多余。。。
&)
so
all
【在 X****r 的大作中提到】
: In case of a function template, template argument deduction is performed
: before the compiler tries to resolve the overloading [13.3.1 paragraph 7].
: In other words, the compiler sees "a*b", then it looks for all overloaded "
: operator*". You have "template operator *(const A&, const A&)
: ;" defined up there, so it tries to deduct the typename T. Note that the
: compiler doesn't look into anything else in this step, including your user-
: defined conversion function. Obviously it cannot f
之所以我想用implicit conversion,就是因为class A
一个一个再重写既麻烦,我又不知道是不是多余。。。
&)
so
all
【在 X****r 的大作中提到】
: In case of a function template, template argument deduction is performed
: before the compiler tries to resolve the overloading [13.3.1 paragraph 7].
: In other words, the compiler sees "a*b", then it looks for all overloaded "
: operator*". You have "template
: ;" defined up there, so it tries to deduct the typename T. Note that the
: compiler doesn't look into anything else in this step, including your user-
: defined conversion function. Obviously it cannot f
h*o
7 楼
I get most of your points. But could you belabor a little on your last
sentence please?
The problem I have is that class A is actually built-in in STL and it has
a lot of non-member binary operations. Class B is defined by me. It is a
variant of class A. What I am looking for is a way to implicitly convert
B to A when invoking any function defined for A.
I don't know if this kind of shortcut exits. It is impossible to define a
base class and it looks verbose to define all combinations of A & B f
【在 X****r 的大作中提到】
: In case of a function template, template argument deduction is performed
: before the compiler tries to resolve the overloading [13.3.1 paragraph 7].
: In other words, the compiler sees "a*b", then it looks for all overloaded "
: operator*". You have "template operator *(const A&, const A&)
: ;" defined up there, so it tries to deduct the typename T. Note that the
: compiler doesn't look into anything else in this step, including your user-
: defined conversion function. Obviously it cannot f
sentence please?
The problem I have is that class A is actually built-in in STL and it has
a lot of non-member binary operations. Class B is defined by me. It is a
variant of class A. What I am looking for is a way to implicitly convert
B to A when invoking any function defined for A.
I don't know if this kind of shortcut exits. It is impossible to define a
base class and it looks verbose to define all combinations of A & B f
【在 X****r 的大作中提到】
: In case of a function template, template argument deduction is performed
: before the compiler tries to resolve the overloading [13.3.1 paragraph 7].
: In other words, the compiler sees "a*b", then it looks for all overloaded "
: operator*". You have "template
: ;" defined up there, so it tries to deduct the typename T. Note that the
: compiler doesn't look into anything else in this step, including your user-
: defined conversion function. Obviously it cannot f
相关阅读
RegEx puzzleLooking for MFC high hand哪里有的BIOS的源码?谢谢 (转载)Any "pretty" code out there?C++ cast 小结license的问题C++文件名读取一问one interview questionerror while loading shared librariesurgent question on open source (GPL licensing) (转载)C++声明细问奇怪的继承问题operator overloading<< or >>Unix Network Programming编译 64/32 位的library (Linux)各位给推荐一个C++ programming performance profiler?问一个排序的问题C++ 弱问一个问一个C++的面试问题one question about initializaiton list