For example this code, I create a new project in codeblocks, add these files, enable the header file and when trying to run it i get:
-------------- Build: Debug in date (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -fexceptions -g -std=c++11 -I..\date -c "C:\Users\kairenne\Documents\programming\chapter 8\monster_generation\date\main.cpp" -o obj\Debug\main.o mingw32-g++.exe -o bin\Debug\date.exe obj\Debug\Date.o Date.h.gch obj\Debug\main.o Date.h.gch: file not recognized: File format not recognized collect2.exe: error: ld returned 1 exit status Process terminated with status 1 (0 minute(s), 1 second(s)) 1 error(s), 0 warning(s) (0 minute(s), 1 second(s))
Date.h
#define DATE_H
class Date
{
private:
int m_year;
int m_month;
int m_day;
public:
Date(int year, int month, int day);
void SetDate(int year, int month, int day);
int getYear() { return m_year; }
int getMonth() { return m_month; }
int getDay() { return m_day; }
};
#endif
Date.cpp
// Date constructor
Date::Date(int year, int month, int day)
{
SetDate(year, month, day);
}
// Date member function
void Date::SetDate(int year, int month, int day)
{
m_month = month;
m_day = day;
m_year = year;
}
Main.cpp
#include "Date.h"
using namespace std;
int main()
{
Date test(2000, 05, 10);
return 0;
}
#ifndef
is missing and I would rather have a constructor likeDate::Date(int year, int month, int day): m_year(year), m_month(month), m_day(day){}
. – lainos88