Error when calling constructor....

Date.h
1
2
3
4
5
6
7
8
9
10
11
12
13
class Date {
#include "Date.h"
using namespace std;

public:
	Date();
	Date(unsigned int year, unsigned int month, unsigned int day);

private:
	unsigned int m_year;
	unsigned int m_month;
	unsigned int m_day;
};


Date.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
...
Date::Date(unsigned int year, unsigned int month, unsigned int day)
{
	m_year= year;
	m_month= month;
	m_day = day;
}
Date::Date()
{
	m_year= 2000;
	m_month= 01;
	m_day = 01;
}
...


Main.cpp
1
2
3
4
5
6
7
8
9
10
11
#include "Date.h"
using namespace std;
int main() {
	Date dateA();
	unsigned int year= 2016;
	unsigned int month= 9;
	unsigned int day= 27;
	Date dateB(year,month,day); //error here

return 0;
}


My error is : error saying "invalid digit 9 in octal constant. Using Eclipse.

The error is when I'm trying to create a Date object from the constructor I created... is my syntax wrong?
THank you!
I can't say exactly what caused the issue in your code, but the error indicates that there's an attempt to use the value 9 in an octal (base 8) number.

It may be related to the following lines (or any other lines that use the same format):
Date.cpp:
1
2
	m_month= 01; 
	m_day = 01;

C++ uses a leading 0 before a number to identify it as octal (base 8). By default, C++ deals with decimal (base 10) numbers. Try removing the leading 0s and see if that helps.

Further reading: http://www.cplusplus.com/doc/hex/
Last edited on
Topic archived. No new replies allowed.