I can't get this to compile what am i doing wrong. This is just a simple class that represents dates (month day yr). I have a feeling what i am doing wrong has to do with the mynames portion both in date.h and date.cpp.
error
Code:
1>date.obj : error LNK2001: unresolved external symbol "private: static char * * date::mnames" (?mnames@date@@0PAPADA)
date.h
Code:
#pragma once
#include "stdafx.h"
#include <ostream>
using namespace std;
class date
{
private:
int month;
int day;
int year;
static char *mnames[];
public:
friend ostream &operator<<(ostream &, const date &);
date(void);
date(int, int, int);
date(date &);
int getMonth();
int getDay();
int getYear();
static char *getMonthName(int i){return mnames[i];}
void setMonth(int m);
void setDay(int d);
void setYear(int y);
void printDate();
void printDateX();
};
date.cpp
Code:
#include <iostream>
#include "date.h"
static char *mnames[]= { "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec" };
date::date(void)
{
day=1;
month=1;
year=1900;
}
date::date(int d, int m, int y)
: day(d), month(m), year(y)
{
}
void date::setMonth(int m)
{
}
void date::setDay(int d)
{
}
void date::setYear(int y)
{
}
int date::getMonth()
{
return month;
}
int date::getYear()
{
return year;
}
int date::getDay()
{
return day;
}
void date::printDate()
{
}
void date::printDateX()
{
cout << mnames[month-1] << " " << day << ", "<< year;
}
ostream& operator<<(ostream &cs, const date &d)
{
cs<<d.month<<"/"<<d.day<<"/"<<d.year<<" ";
return cs;
}