Rob-e
April 21st, 2008, 08:18 PM
k, im a nub at this and i dont know what i did wrong, maybe someone can help me out, maybe this is a common error? i appreciate your help
made using geany and g++ if it matters
the errors are:
/tmp/ccYnZ7dN.o: In function `main':
test.cpp:(.text+0x19c): undefined reference to `Date::setDay(int)'
test.cpp:(.text+0x1a7): undefined reference to `Date::getDay()'
collect2: ld returned 1 exit status
it has 3 parts
birthday.h:
#ifndef BIRTHDAY_H
#define BIRTHDAY_H
class Date
{
public:
void setMonth(int month);
int getMonth();
void setDay(int day);
int getDay();
void setYear(int year);
int getYear();
int DaysInMonth(int inMonth);
private:
int Month;
int Day;
int Year;
};
#endif
birthday.cpp:
#include <iostream>
#include "birthday.h"
void Date::setMonth(int month)
{
month = Month;
}
int Date::getMonth()
{
return Month;
}
void Date::setDay(int day)
{
day = Day;
}
int Date::getDay()
{
return Day;
}
void Date::setYear(int year)
{
year = Year;
}
int Date::getYear()
{
return Year;
}
int DaysInMonth(int inMonth)
{
switch(inMonth)
{
case 1:
return 31;
break;
case 2:
return 32;
break;
case 3:
return 33;
break;
case 4:
return 34;
break;
case 5:
return 35;
break;
case 6:
return 36;
break;
case 7:
return 37;
break;
case 8:
return 38;
break;
case 9:
return 39;
break;
case 10:
return 310;
break;
case 11:
return 311;
break;
case 12:
return 312;
break;
default:
return 0000;
break;
}
}
and a testing thing called test.cpp:
#include "birthday.h"
#include <iostream>
using namespace std;
#include <string>
int main(int argc, char** argv)
{
Date date;
date.setDay(5);
cout << date.getDay() << endl;
return 0;
}
made using geany and g++ if it matters
the errors are:
/tmp/ccYnZ7dN.o: In function `main':
test.cpp:(.text+0x19c): undefined reference to `Date::setDay(int)'
test.cpp:(.text+0x1a7): undefined reference to `Date::getDay()'
collect2: ld returned 1 exit status
it has 3 parts
birthday.h:
#ifndef BIRTHDAY_H
#define BIRTHDAY_H
class Date
{
public:
void setMonth(int month);
int getMonth();
void setDay(int day);
int getDay();
void setYear(int year);
int getYear();
int DaysInMonth(int inMonth);
private:
int Month;
int Day;
int Year;
};
#endif
birthday.cpp:
#include <iostream>
#include "birthday.h"
void Date::setMonth(int month)
{
month = Month;
}
int Date::getMonth()
{
return Month;
}
void Date::setDay(int day)
{
day = Day;
}
int Date::getDay()
{
return Day;
}
void Date::setYear(int year)
{
year = Year;
}
int Date::getYear()
{
return Year;
}
int DaysInMonth(int inMonth)
{
switch(inMonth)
{
case 1:
return 31;
break;
case 2:
return 32;
break;
case 3:
return 33;
break;
case 4:
return 34;
break;
case 5:
return 35;
break;
case 6:
return 36;
break;
case 7:
return 37;
break;
case 8:
return 38;
break;
case 9:
return 39;
break;
case 10:
return 310;
break;
case 11:
return 311;
break;
case 12:
return 312;
break;
default:
return 0000;
break;
}
}
and a testing thing called test.cpp:
#include "birthday.h"
#include <iostream>
using namespace std;
#include <string>
int main(int argc, char** argv)
{
Date date;
date.setDay(5);
cout << date.getDay() << endl;
return 0;
}