-7
在我的isEmpty函數中,我想檢查對象是否處於安全空狀態,如果是,則返回true。當我在函數上方的構造函數中聲明的denom = -1時,會出現安全空白。我如何訪問這個? 編輯:道歉,我誤讀行錯誤。我錯過了另一行使用的denom,並修復了錯誤。對不起,浪費你的時間:(來自構造函數的訪問值
using namespace std;
namespace sict{
class Fraction{
private:
int num; // Numerator
int denom; // Denominator
int gcd(); // returns the greatest common divisor of num and denom
int max(); // returns the maximum of num and denom
int min(); // returns the minimum of num and denom
public:
void reduce(); // simplifies a Fraction number by dividing the
// numerator and denominator to their greatest common divisor
Fraction(); // default constructor
Fraction(int n , int d=1); // construct n/d as a Fraction number
void display() const;
bool isEmpty() const;
};
};
** *實現
#include "Fraction.h"
using namespace std;
namespace sict
{
Fraction::Fraction()
{
denom =-1; // safe empty state
}
bool Fraction::isEmpty() const
{
//How do I access denom
}
}
相同的方式,在你的構造做了對不起,但我不 –
您是如何在構造函數中使用它的? – skypjack
isEmpty是Fraction類的成員函數,因此所有成員變量/函數都可以訪問。 –