我有一個類Date。讓日期是:暴露字段的常量引用
class Date
{
private:
unsigned int _day;
unsigned int _month;
unsigned int _year;
public:
const unsigned int& Day;
const unsigned int& Month;
const unsigned int& Year;
Date() : Day(_day), Month(_month), Year(_year)
{ }
}
出於某種原因,調用構造函數日,月,年後不點/參考_day,_month和_year。
我的一個猜測是他們在內存分配給類之前被設置,我將如何去解決這個問題(也就是在內存分配後設置引用)?
在此先感謝!
編輯:更多信息
_day(如爲)的值當我得到日的值不返回。我看到一個看似隨機的數字。
你確定他們設置錯了嗎?什麼讓你有那個想法?請提供更多信息。 – StilesCrisis
editted for more info –