Using a passed reference

Probably a simply problem but I just don't get it.

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
// define structure
typedef struct {
  int day;
  int month;
  int year;
} Date;

//function defn
void dateFunction (Date *num);

//main function
main ()
{
  Date date;

  dateFunction(&date);

}

//date function
void dateFunction (Date *num)
{
  num.day = 1;
  num.month = 1;
  num.year = 1;
}


My problem is i have some repetitive tasks that i'd like to use a function for, but can't seem to get the syntax right. I get the following compiler error for all 3 initializations:

"request for member ‘day’ in ‘date’, which is of non-class type ‘Date*’"

any help?
num is a pointer, not a reference.
Date &
SOLVED

i changed the dateFunction to:

1
2
3
4
5
6
void dateFunction (Date *num)
{
  num->day = 1;
  num->month = 1;
  num->year = 1;
}


... and it worked.
Last edited on
Topic archived. No new replies allowed.