Accessing Private Member

Hello people...I just want this program to print out a simple statement...but I'm having problems accessing the private member...help please...


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
using namespace std;

class Date {
	void set(int y, int m, int d);
	int get_year;
	int get_month;
	int get_day;
	Date();
	Date(int y, int m, int d);
	void print();
	Date plus(int num);
};
***********************************************
#include "date.h"

Date::Date()	//default constructor
{
  day = 1;
  month = 1;
  year = 1900;
}

Date::Date(int Month, int Day, int Year)  //  construct from month/day/year
{
  month = Month;
  day = Day;
  year = Year;
}

void Date::setDay(int d)
{
  day = d;
}

void Date::setMonth(int m)
{
  month = m;
}

void Date::setYear(int y)
{

  year = y; 

}

int Date::getDay() const
{
  return day;
}

int Date::getMonth() const
{
  return month;
}

int Date::getYear() const
{
  return year;
}

void Date::print() const
{
  if (year < 10) cout <<'0';
  cout << year << ",";
  if (month < 10) cout <<'0';
  cout << month << ",";
  if (day < 10) cout <<'0';
  cout << day << "." << endl;

}

*******************************************************
#include "date.h"
 int main()
 {
	 Date begin;
	 Date check_in;
	 int y, m, d;
	 begin.set (0, 0, 0);


	 cout << "Please enter Year, Month, and Day: ";
	 cin >>y>>m>>d;
	 check_in.set (y, m, d);

	 cout << "You have entered: ";
	 check_in.print();

	 return 0;
 }


You can't access anything from your class from main() or anywhere else other than the class itself because every member is private.

Read: http://www.cplusplus.com/doc/tutorial/classes/ for more class information
Last edited on
Expanding on what bluezor said, your functions/constructor are also private (they can be declared public/protected/private as well), so make them public.
Screw that.

1
2
#define private public
#define class struct 



And throw off those shackles of bondage!!!
Last edited on
^Lolz. You forgot:

 
#define protected public 
Last edited on
Topic archived. No new replies allowed.