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 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: 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 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: 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 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: 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 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: 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
相关阅读
能否通过父类指针来复制子类对象?DL for JVM对firebase in production 的评论关于多线程锁:锁代码还是锁资源?陆奇 在 CMU 博士后的导师是印度人 M. Satyanarayanan请教Android 编程王垠:微软感受 (转载)有做过PACS系统的高手么?神经网络识别多个目标如何正确使用WebGrid请教个javascript的问题 (转载)python 画图哪个库最好用?[申请]葵花宝典(Programming)版版主——philistin (转载)面向国内的web, hosting一般推荐哪个公司?清华CS排名甩Princeton一条街航线为何不能进行智能化管理?cnn 如何做到 scale invariant有什么上古算法可以用大数据复活的?ML 最讨厌的就是搞了太多专业名词号召全体海外华人成立统一组织 (转载)