#Not sure why I'm unable to use certain functions. Set containers in Polymorphism
23 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
!format
Errors are in GetAppointmentDates, GetGroomers, GetAppointmentsByDates, and are commented under the problem.
what type does appointment->GetDateTime() return?
it must be a std::string. what does your error messages say?
you should have a "callstack" of how it tried to resolve the tempalte in your output window in visual studio if your using it
I'm using clion by jetbrains. appointment->GetDateTime() returns a DateTime class object. The DateTime Class takes in two strings. I hope that answers you question.
The error message I'm getting is No matching member function for call to 'insert' So I believe that the issue is that trying to call the insert function incorrectly?
I'm not sure what callstack is. Is it a VS Code thing? I'm not too good with remembering all of the functions without looking at my notes or online.
your trying to insert a DateTime into a set that only takes std::string so there wouldnt be a function insert(DateTime)
Ok, I think I get it. So I need to turn it into string and then inset that into the set right?
can you not change the set to accept DateTime?
change std::set<std::string> to std::set<DateTime>
but if this is some sort of assignment of yours and you cant alter that then that would be a way to do it too yes
Unfortunately it says to " - Return type is a set of strings"
convert to a string it is
So should be the last question. Does the .push_back(), also need to be converted to a string?
//error No matching member function for call to 'push_back'
appointments.push_back(appointment);
I tried converting to a stringstream, but I got the same error.
appointments.push_back(ss.str());
what does the DateTime class look like?
does it have a function tostring or soomething like that?
are you meant to create one?
new classes you create dont have any implicit to string function, you have to do it yourself
!format
#ifndef DATE_TIME_H
#define DATE_TIME_H
#include <string>
class DateTime {
private:
int month_;
int day_;
int year_;
int hours_;
int mins_;
std::string meridiem_;
public:
DateTime(std::string date, std::string time = "12:00 am");
int GetMonth() const { return month_; }
int GetDay() const { return day_; }
int GetYear() const { return year_; }
int GetHours() const { return hours_; }
int GetMins() const { return mins_; }
// Getters
// GetDate() - returns the date in the following format 07/08/2023
std::string GetDate();
// GetTime() - returns the time in the following format 9:00am
std::string GetTime();
// Setters
void SetDate(std::string date);
void SetTime(std::string time);
// Other Methods
friend std::ostream& operator<<(std::ostream& out, const DateTime& dateTime);
};
#endif // DATE_TIME_H
It doesn't have a to string function, but is that what I'll need for the push_back function? It didn't work like the other methods.
it does, you have a GetDate and GetTime that returns the date and time as strings.
something like set.insert(dt.GetDate() + " " + dt.GetTime()) should work for you
ok thank you so much!
@main fern Has your question been resolved? If so, type !solved :)
!solved