I cannot run this program because 'Date::Date()' is private and error at 'Date toDay' in main. However if my members are in public, not private then I get no problem. Can someone please tell me what my mistakes are? How can I access these private members? Thank you in advance.
Date.h file: #ifndef DATE_H_INCLUDED #define DATE_H_INCLUDED class Date { private: int m_nMonth; int m_nDay; int m_nYear; Date() {} // private default constructor public: Date(int nMonth, int nDay, int nYear); void SetDate(int nMonth, int nDay, int nYear); int GetMonth() { return m_nMonth; } int GetDay() { return m_nDay; } int GetYear() { return m_nYear; } }; #endif // DATE_H_INCLUDED Date.cpp file: #include "Date.h" // Date constructor Date::Date(int nMonth, int nDay, int nYear) { SetDate(nMonth, nDay, nYear); } // Date member function void Date::SetDate(int nMonth, int nDay, int nYear) { m_nMonth = nMonth; m_nDay = nDay; m_nYear = nYear; } main.cpp file: #include "Date.h" #include <iostream> using namespace std; int main() { Date toDay; toDay.SetDate(10, 12, 1962); cout << toDay.GetMonth() << endl; cout << toDay.GetDay() << endl; cout << toDay.GetYear() << endl; return 0; }