Linking C function with C++ object file


This is a my C function: int Dow(long year, long month, long day)
{
if(month < 3)
{
month += 12;
year -= 1;
}
return (day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 - year / 100 + year / 400) % 7;
}



it's my C++ program's header file. #ifndef HEADER_H
#define HEADER_H

long Dow(long, long, long);

namespace Project
{
class Calender
{
public:
Calender(int y, int m);

int IsLeapYear();

int CountDays();

int DayOfWeek(int a);

void print();

private:
int year;
int month;
};
}
#endif



$ it's abc.cpp file
#include "header.h"
#include <iostream>

//extern "C" long Dow(long, long, long);

long Dow(long, long, long);


namespace Project
{
Calender::Calender(int y=0, int m=0)
{
year = y;
month = m;
}

int Calender::IsLeapYear()
{
long x = year / 100;
if(year % 4 == 0)
return (x % 4 == 0) ? 1 : 0;
return 0;
}

int Calender::CountDays()
{
int array[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
if(IsLeapYear() == 1 && month == 2)
return 29;
return array[month];
}

int Calender::DayOfWeek(int a)
{
if((IsLeapYear() == 1 && (month == 2 && a >29)) || (a > CountDays()))
throw a;
return Dow(year, month, a);
}

void Calender::print()
{
std::cout << year << ":" << month << std::endl;
}

}





now i want to create an object file of this CPP file
bt above highlited Dow (C function) shud also get called.

guyz HOW SHOULD I COMPILE IT???
thnx
regards
Last edited on
Topic archived. No new replies allowed.