TIMERS.h:

#include "includes.h"


class servtime
{
public:
	int sec()
	{
		int sec;
		time_t rawtime;
		tm * timeinfo;
		time(&rawtime);
		timeinfo=localtime(&rawtime);
		sec=timeinfo->tm_sec;
		return sec;
	}
	int mint()
	{
		int min;
		time_t rawtime;
		tm * timeinfo;
		time(&rawtime);
		timeinfo=localtime(&rawtime);
		min=timeinfo->tm_min;
		return min;
	}
	int hour()
	{
		int hour;
		time_t rawtime;
		tm * timeinfo;
		time(&rawtime);
		timeinfo=localtime(&rawtime);
		hour=timeinfo->tm_hour;
		return hour;
	}
	int day()
	{
		int day;
		time_t rawtime;
		tm * timeinfo;
		time(&rawtime);
		timeinfo=localtime(&rawtime);
		day=timeinfo->tm_mday;
		return day;
	}
	int month()
	{
		const int MONTHS[]={1,2,3,4,5,6,7,8,9,10,11,12};
		int month;
		time_t rawtime;
		tm * timeinfo;
		time(&rawtime);
		timeinfo=localtime(&rawtime);
		month=timeinfo->tm_mon;
		return MONTHS[month];
	}
	int years()
	{
		int year;
		time_t rawtime;
		tm * timeinfo;
		time(&rawtime);
		timeinfo=localtime(&rawtime);
		year=timeinfo->tm_year;
		return (1900+year);
	}
};

LOGMSG.h:

//#include "includes.h"
#include "TIMERS.h"

servtime TM;
void LOGMSG(string logmsg)
{
	cout << logmsg.c_str() << TM.years();
}

main.cpp

#include "includes.h"
#include "TIMERS.h"
#include "LOGMSGs.h"
int main()

{
	LOGMSG("test");
}

but i got errors:

Error 9 error C2228: left of '.years' must have class/struct/union
Error 8 error C2079: 'TM' uses undefined class 'servtime'
Error 7 error C2011: 'servtime' : 'class' type redefinition

whats wrong !!!

Put code guards in timers.h fixed the problem for me. Note the preprocessor directives at the top and bottom of the file. This prevents the preprocessor from parsing the file more than once in the same *.cpp file.

#ifndef _TIMERS_H
#define _TIMERS_H
#include "includes.h"


class servtime
{
public:
	int sec()
	{
		int sec;
		time_t rawtime;
		tm * timeinfo;
		time(&rawtime);
		timeinfo=localtime(&rawtime);
		sec=timeinfo->tm_sec;
		return sec;
	}
	int mint()
	{
		int min;
		time_t rawtime;
		tm * timeinfo;
		time(&rawtime);
		timeinfo=localtime(&rawtime);
		min=timeinfo->tm_min;
		return min;
	}
	int hour()
	{
		int hour;
		time_t rawtime;
		tm * timeinfo;
		time(&rawtime);
		timeinfo=localtime(&rawtime);
		hour=timeinfo->tm_hour;
		return hour;
	}
	int day()
	{
		int day;
		time_t rawtime;
		tm * timeinfo;
		time(&rawtime);
		timeinfo=localtime(&rawtime);
		day=timeinfo->tm_mday;
		return day;
	}
	int month()
	{
		const int MONTHS[]={1,2,3,4,5,6,7,8,9,10,11,12};
		int month;
		time_t rawtime;
		tm * timeinfo;
		time(&rawtime);
		timeinfo=localtime(&rawtime);
		month=timeinfo->tm_mon;
		return MONTHS[month];
	}
	int years()
	{
		int year;
		time_t rawtime;
		tm * timeinfo;
		time(&rawtime);
		timeinfo=localtime(&rawtime);
		year=timeinfo->tm_year;
		return (1900+year);
	}
};
#endif

thnx :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.