Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9245701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:19:26+00:00 2026-06-18T09:19:26+00:00

I have a class Date. let date be: class Date { private: unsigned int

  • 0

I have a class Date. let date be:

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)
    {  }
}

For some reason, after the constructor is called Day, Month and Year do not point/refer to _day, _month and _year.

One guess of mine would be that they are being set before memory is allocated to the class, how would i go about solving this issue (aka setting the references after memory allocation)?

Thanks in advance!

EDIT: More info

The value of _day (for eg) is not returned when i get the value of Day. I get a seemingly random number.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:19:27+00:00Added an answer on June 18, 2026 at 9:19 am

    It’s not very clear what you want to achieve. In your Date class you can access _date, _month, _year directly why do you want to set another reference?

    But to answer you question

    The value of _day (for eg) is not returned when i get the value of Day. I get a seemingly random number

    Actually, the values are being returned, but you are getting garbage because _day, _month, and _year are just uninitialized integers. You need to initialize them in the initializer list first:

    Date() : _day(0), _month(1), _year(2), Day(_day), Month(_month), Year(_year)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class: public class Day { public int Date { get;
Let's say I have an object: public class CustomObj { DateTime Date { get;
Let's say I've got class: class Bad_Date { private: const char* _my_msg; public: const
Let's propose that I have the following class Public MyClass{ Date date; //Mutable getters
Let's say I have following POJO's using Hibernate. public class User { private String
I have a list of objects called Activity: class Activity { public Date activityDate;
Say I have the following simple java bean: class MyBean { private Date startDate;
Let's say I have the following Django model: class Info(models.Model): instrument = models.ForeignKey('Instrument') date
Let's say I have a class Voucher: public class Voucher { public Guid Id
Let's say I have a class Comment and I have a private field named

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.