由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - An object of A automatically converted to an object of B.
相关主题
问个overloading new operator的问题[合集] 又被羞辱了一把... (转载)
why use static function here?再一个问题c++
请问关于overloading <<c++ operator overloading question
why copy assignment operator returns non-const type?question overloading ++ error
为什么在overloading中,friend <<不能读取private值呢?请问一个implicit conversion的问题(C++)
C++ namespace 弱问one question about overloading operator delete
C++ operator = overloading用copy & swap有啥优点这段code有啥问题?
C++: define a reference always reference the same objectHow to overload global new operator?
相关话题的讨论汇总
话题: object话题: operator话题: converted话题: const
进入Programming版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
Question: In what two ways can an object of type A be automatically
converted into an object of B in C++?
The answer: .... (the first method omitted)
Another method is needed if we wish to be able to convert into objects of
type B when the class declaration is not accessible, for example, suppose B
was the type double: we cannot write a new constructor for doubles. This is
done by defining an operator in the class A whose name is B so we include
the line
operator B() const;
in the class declaration for A. When we define the operator, we code it as
B::operator A() const;
{ // create object of type B and return it ... }
这个答案是不是就是在A里面定义一个函数成员,来overload B()呢?
如果B是double,这个declaration就是
operator double() const;
后面那句答案是不是写反了?我觉得应该是
A::operator B() const;
1 (共1页)
进入Programming版参与讨论
相关主题
How to overload global new operator?为什么在overloading中,friend <<不能读取private值呢?
operator overloading (C++)C++ namespace 弱问
which style do you prefer?C++ operator = overloading用copy & swap有啥优点
问题的根源找到了C++: define a reference always reference the same object
问个overloading new operator的问题[合集] 又被羞辱了一把... (转载)
why use static function here?再一个问题c++
请问关于overloading <<c++ operator overloading question
why copy assignment operator returns non-const type?question overloading ++ error
相关话题的讨论汇总
话题: object话题: operator话题: converted话题: const