This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: how come #include "*.cpp" works?

On Thu, May 11, 2006 at 09:09:33PM +0200, Klaas Thoelen wrote:
> This seems a little strange to me. Does anybody know what's wrong here?
> Thanks and regards,
> Klaas Thoelen

It's just a classic mistake, pretty easily fixed with the following:

> datum.h
> ******

Add this:

#ifndef DATUM_H
#define DATUM_H

> class Date {
> public:
>    Date();
>    Date(int dd, int mm, int yy);
>    int day();
>    int month();
>    int year();
>    static void set_default(int, int, int);
>    Date& add_year(int);
>    Date& add_month(int);
>    Date& add_day(int);
>    Date& print();
> private:
>    int d, m, y;
>    static Date default_date;
>    static bool is_leapyear(int);
>    static int daysinmonth(int, int);
> };

#endif /* DATUM_H */

That ifndef construct is a one-way trap-door to prevent a doubly included file
from clobbering itself. Pretty standard.

> datum.cpp
> ********
> #include "datum.h"
Probably should place this after your standard includes below.

> #include <iostream>
> #include <assert.h>
> using namespace std;

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]