Hi,
I'm writing a "Date" class and it's fully functioning, including the output manipulators, but the issue I have is when creating a class the has a "Date" instance in it. It, then, doesn't compile because it says there are multiple definitions of the manipulator functions.
I'll lay out, below, the basic layout of my Date class (and supporting classes):
- Date class
- Header files
- date.h (contains #includes for dateIOManip.h and dateManip.h)
- dateIOManip.h (contains working code for IO manipulators)
- dateManip.h (contains declarations for dateManip.cc)
- day.h (contains declarations for day.cc)
- month.h (contains declarations for month.cc)
- time.h (contains declarations for time.cc...used in day.h)
- year.h (contains declarations for year.cc)
- Source files
- Header files
************ The following is unwritten ************
- Memo class
- Header files
- memo.h
- Source files
- Header files
- Calendar class
- Header files
- calendar.h
- Source files
- Header files
************ The above is unwritten ************
The Date class, above, works alone. I can create instances of it in a main.cc and utilize everything within it well, including the IO manipulators.
But my goal is to use instances of it in the Memo class. And the Memo class will be used within my Calendar class above. Ultimately, to create a flexible text-based events calendar.
When I put an "#include date.h" (which includes dateManip.h and dateIOManip.h for a fully working Date class) within my memo.h, I get a long series of errors right at the end of compile time saying that the functions within dateIOManip.h have become multiple definitions within memo.o, and were first defined at dateIOManip.h
The following is a piece of my dateIOManip.h:
Date::FlagMap Date::Flags;
struct fullManip {};
void full(fullManip x) {}
typedef void(*fullPtr)(fullManip);
ostream &operator << (ostream &out, fullPtr) {
Date::Flags[&out] = "full";
return out;
}
ostream &operator << (ostream &out, Date &rhs) {
string pick = "full";
Date::FlagMap::iterator iter = Date::Flags.find(&out);
if(iter==Date::Flags.end())
pick = "full";
else
pick = iter->second;
if(pick == "full")
out << rhs.thisDay.strVal << ", " << rhs.thisMonth << " " << rhs.thisDay << ", " << rhs.thisYear;
(the above has MANY different manipulators, so it is not just a single manipulator)
The above working code would look like the following:
#include <iostream>
#include "date.h"
using namespace std;
int main(int argc, char** argv) {
Date mine = Date(Month(12), Day(25), Year(2010));
cout << full << mine << endl;
cin.get();
return 0;
}
The output from above would be:
Saturday, December 25, 2010
The error I get when I #include "date.h" within my memo.h is:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4/new:105: multiple definition of `full(fullManip)'
build/Debug/GNU-Linux-x86/main.o:/home/josh/Calendar2/Date/dateIOManip.h:16: first defined here
build/Debug/GNU-Linux-x86/Memo/memo.o: In function `fullTime(fullTimeManip)':
Can someone help me correct this? I've been thinking of ways to work around this but I'm unsure what to do.
Also, I do have include guards on all of my header files (they're automatically placed there by NetBeans IDE)
PS: I work within Gentoo Linux on g++4.3.4
Thanks in advance!
-Josh