l*********s 发帖数: 5409 | 1 You will be creating three classes. The first class is called Number, which
supports three operations:
“display”, “==”, and “+”.
1. display: This operation displays the Number itself in its original form (
I will explain later).
2. ==: This operation returns true if two Numbers are numerically the same.
3. +: This operation adds the number itself with another number and returns
a third number
whose numeric value is equal to the sum of the numeric values of the former
two. |
l*********s 发帖数: 5409 | 2 学艺不精,遇到点问题:
Number类应该是个虚拟类吧,但是加法函数的接口怎么写呢?做为方法的话,返回值是
Number的话Fraction和Integer子类无法实例化,不写又不合规定,加上参数次序的问
题,怎么都很别扭!
which
(
returns
former
【在 l*********s 的大作中提到】 : You will be creating three classes. The first class is called Number, which : supports three operations: : “display”, “==”, and “+”. : 1. display: This operation displays the Number itself in its original form ( : I will explain later). : 2. ==: This operation returns true if two Numbers are numerically the same. : 3. +: This operation adds the number itself with another number and returns : a third number : whose numeric value is equal to the sum of the numeric values of the former : two.
|
b*******s 发帖数: 5216 | 3 你以前没接触过c++吗?
【在 l*********s 的大作中提到】 : 学艺不精,遇到点问题: : Number类应该是个虚拟类吧,但是加法函数的接口怎么写呢?做为方法的话,返回值是 : Number的话Fraction和Integer子类无法实例化,不写又不合规定,加上参数次序的问 : 题,怎么都很别扭! : : which : ( : returns : former
|
N******K 发帖数: 10202 | 4 用template不就行了?
which
(
returns
former
【在 l*********s 的大作中提到】 : You will be creating three classes. The first class is called Number, which : supports three operations: : “display”, “==”, and “+”. : 1. display: This operation displays the Number itself in its original form ( : I will explain later). : 2. ==: This operation returns true if two Numbers are numerically the same. : 3. +: This operation adds the number itself with another number and returns : a third number : whose numeric value is equal to the sum of the numeric values of the former : two.
|
b***i 发帖数: 3043 | 5 你的要求不清楚阿.你先说这里有三个类,然后就说了第一个类叫Nmber。然后这里又提
到Fraction。那么他们的要求到底是什么?
【在 l*********s 的大作中提到】 : 学艺不精,遇到点问题: : Number类应该是个虚拟类吧,但是加法函数的接口怎么写呢?做为方法的话,返回值是 : Number的话Fraction和Integer子类无法实例化,不写又不合规定,加上参数次序的问 : 题,怎么都很别扭! : : which : ( : returns : former
|
X****r 发帖数: 3557 | 6 Both operator == and operator + likely need to use double dispatch
for a meaningful implementation.
which
(
returns
former
【在 l*********s 的大作中提到】 : You will be creating three classes. The first class is called Number, which : supports three operations: : “display”, “==”, and “+”. : 1. display: This operation displays the Number itself in its original form ( : I will explain later). : 2. ==: This operation returns true if two Numbers are numerically the same. : 3. +: This operation adds the number itself with another number and returns : a third number : whose numeric value is equal to the sum of the numeric values of the former : two.
|
l*********s 发帖数: 5409 | 7 就是顶贴的要求,已经搞定了,惭愧。
【在 b***i 的大作中提到】 : 你的要求不清楚阿.你先说这里有三个类,然后就说了第一个类叫Nmber。然后这里又提 : 到Fraction。那么他们的要求到底是什么?
|
l*********s 发帖数: 5409 | 8 是的,一开始想歪了。
【在 N******K 的大作中提到】 : 用template不就行了? : : which : ( : returns : former
|