Help with error on a constructor

I am getting the following error:

"error C2064: term does not evaluate to a function taking 1 arguments"

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


#include <iostream>
#include <iomanip>
#include "Date.h" //include definition of class Date from Date.h
#include <stdexcept>

using namespace std;

//Date constructor(Should do rage checking)
Date::Date(int m, int d, int y)
{
	setDate( month, day, year);
}//End of Constructor

void Date::setDate(int m, int d, int y)
{
	month(m);
	day(d);
	year(y);
}


void Date::setMonth(int m)
{
	if(m >= 1 && m <= 12)
		month = m;
	else
		throw invalid_argument("Month must be 1-12");
}


void Date::setDay(int d)
{
	if(d > 0 && d <= 31)
		day = d;
	else
		throw invalid_argument("Days must be 1-31");
}

void Date::setYear( int y)
{
	if(y >= 0)
		year = y;
	else
		throw invalid_argument("Year must be 0 or greater.");
}


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

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

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

void Date::print()
{
	cout << month << '/' << day << '/' << year << endl;
}/


I am not sure why I getting the error. I took the constructor from another program that works and modified to this one but I did not change anything that would alter the behavior of the program.

Any suggestions?
Last edited on
I believe the data member month/day/year of the Date class are not class type, if they are int type, you cannot init them in that way except in Date constructor's initialization list. So use assignment to fix the error.
Eric,

I am new in programming. Can you explain how I can use the assignment to fix it?

Thanks.
month = m;
day = d;
year = y;

Or you can:

Date::Date(int m, int d, int y) : month(m), day(d), year(y) {}

so you don't need to call setDate() from the constructor.
Topic archived. No new replies allowed.