This is kinda like "part 2" of my other post. Have also been working on this one for about 3 weeks.

A suggestion was made that I should consider using the map container to accomplish what I want. My textbook doesn't talk about maps but I found some info on the 'net. However, when I use it I get the following error:

/home/cody/Projects/enumeration/src/enumeration.cpp:33: no match for ` std::ostream& << const Date&' operator

Am I not using map correctly? (I'm using my new classes instead of fundamental types).

Prior to using the map, I had vector<T> containers for each class and output them seperately; when I changed it to a map is when the errors occurred.

I'm aware that there's a few better ways to have designed my program, but due to time constraints, I'd rather not rewrite it.

12 Years
Discussion Span
Last Post by jwenting

Look at the error and tell why it has anything at all to do with map<T>.
It says you failed to define operator<< for your enumeration class.

P.S. don't post your source as attachments if you want us to look at it.
Take the relevant parts and paste those inside code tags (that means NOT to post hundreds of lines of code that does in no way relate to the problem you're having).


The only reason I think it's an issue w/ the map is because the error didn't occur when using vector<T>'s or standard arrays. It only happened when I switched to map<>. I do have the << and >> operators overloaded, as shown in the last code block. This is the same implementation that I've used in previous programs w/ no problem, but it's the first time I've used it w/ map<>. That's why I don't know if I screwed up implementing it for map.

As I said, an email friend suggested using map<> instead of vector<T> to create this. My original intent was to have a vector<Date> and vector<Event> and create another vector<T> that took them both and somehow could sort them based on Date (kinda like Excel). But he told me that map containers would be easier.

#include <iostream>
#include <map>
#include "date_class.h"
#include "Events_class.h"

using namespace std;

int main()
	char quit;
	map <Date, Event> event_date;
	map <Date, Event>::iterator iter;

	cout << "Enter the date of an event (format: mm/dd/yyyy) and the event name" << endl;
		Date d_in;
		Event e_in;
		cin >> d_in >> e_in;
		event_date[d_in] = e_in;

		cout << "Do you have more entries? Enter 'y' or 'n'" << endl;
		cin >> quit;
	}while (quit != 'n');

	for (iter = event_date.begin(); iter != event_date.end(); iter++)
		cout << iter->first << "\t" << iter->second << endl;
	return 0;
//--------Overload output operator--------------
inline ostream & operator<< (ostream & out, Date & date)
	return out;

//--------Overload input operator---------------
inline istream & operator>> (istream & in, Date& date)
	return in;

What does the iterator attempt to call the operator on though?

Not quite sure but I believe your iterator will return a pair<Date, Event> which will of course know of no operator<<.
You'd have to dereference the Event out of that pair using .second so you'd get iter->pair.second (or possibly iter->pair->second)

Mind that I'm not 100% certain about this, but look in that direction for your solution.


I'll look into that. Your right; I am trying to output a Date and Event. If I had the <<operator overloaded for both Date and Event, would that work?


you will need to overload the operator<< for both Date and Event for certain.
Whether that alone is enough to have your program do what you want you'll have to try, but likely you'll need to print both key and value manually by accessing the pair which is the data structure pointed to by the iterator and calling its "first" and "second" members (which then triggers your operators).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.