#include <iostream>
#include <map>
using namespace std;
int passcode = 876;
int pcEntry;
bool pcComplete = false;
string mapEntry;
map <string, bool> carlist;
// We create a function to post the car menu
void carMenu();
// We create a function that checks if the correct code is put in, will be needed for later
int checkPasscode(bool) {
// If the pcComplete is false, we run this code allowing the Manager to input the passcode for adding cars
if (pcComplete == false) {
cout<< "Please enter the manager passcode:" << endl;
cin >> pcEntry;
cout<< pcEntry << endl << endl;
}
if (pcEntry == passcode) {
cout << "Good day Stock Manager!" << endl;
cout << "Please follow the format when adding a new car: {Car, RentalStatus} " << endl;
cin >> mapEntry;
carlist.insert({mapEntry});
}
return pcComplete;
}
// The main function
int main() {
checkPasscode(pcComplete);
return 0;
}
#"No Instance of Overloaded function"
45 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 run !howto ask.
So yeah
I've gotten my first assignment and I'm starting it early. We're creating a Car rental menu, I was gonna use dictionaries since I'm used to Python and Luau then I found out C++ doesn't have dictionaries, it has maps
This is a classic.
So because of how C++ overloading works, it will look at the argument type, then try to look for a matching overload. If it fails with a match, you don't get a "you should use type X, you used Y", but this error instead.
In this case you have to look at what it expects for insert (which is non-trivial for templated code):
An example gives: mymap.insert ( std::pair<char,int>('a',100) );
So in your case you need to pass: std::pair<string, bool>("foo", true) or something like that.
If you want to use it in a more sane way, use emplace to infer the std::pair for you:
mymap.emplace("foo", true);
Alright so I've given it a quick read through but another issue has popped up
I'll pin this somewhere, thanks for that
if (pcEntry == passcode) {
cout << "Good day Stock Manager!" << endl;
cout << "Please enter the car model:" << endl;
cin >> value1;
cout << "Please enter the rental status: true or false (case sensitive):" << endl;
cin >> value1;
carlist.emplace(value1,value2);
}
Pretty much all I changed in the entire thing
I did a little looking on stackoverflow for the operator thing but none of it makes any sense
@rigid pond Has your question been resolved? If so, run !solved :)
What is your “value2”?
value2 is a bool
Do you have the full code?
Yeah gimmie a moment
#include <iostream>
#include <map>
using namespace std;
int passcode = 876;
int pcEntry;
bool pcComplete = false;
string mapEntry;
string value1;
bool value2;
map <string, bool> carlist;
// We create a function to post the car menu
void carMenu();
// We create a function that checks if the correct code is put in, will be needed for later
int checkPasscode(bool) {
// If the pcComplete is false, we run this code allowing the Manager to input the passcode for adding cars
if (pcComplete == false) {
cout<< "Please enter the manager passcode:" << endl;
cin >> pcEntry;
cout<< pcEntry << endl << endl;
}
if (pcEntry == passcode) {
cout << "Good day Stock Manager!" << endl;
cout << "Please enter the car model:" << endl;
cin >> value1;
cout << "Please enter the rental status: true or false (case sensitive):" << endl;
cin >> value1;
carlist.emplace(value1,value2);
}
return pcComplete;
}
// The main function
int main() {
checkPasscode(pcComplete);
return 0;
}
What compiler? This compiles with Clang and GCC
GCC
What version?
Works on 14.x
With Clang
If that was what you were testing.
Also works on msvc
using namespace std;
int passcode = 876;
int pcEntry;
bool pcComplete = false;
string mapEntry;
string value1;
bool value2;
map <string, bool> carlist;
// We create a function to post the car menu
void carMenu();
// We create a function that checks if the correct code is put in, will be needed for later
int checkPasscode(bool) {
// If...
I'll check that out at school today
I restarted vsc and it works now
👍
gonna revisit that link u sent me before and check how to output it now
Thanks for the assistance
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity
cout << "Please enter the car model:" << endl;
cin >> value1;
cout << "Please enter the rental status: true or false (case sensitive):" << endl;
cin >> value1;
Did you mean to stream to value1 on both statements?
To my untrained eye, the second instance should be to a temp string, which is subsequently compared with either "true" or "false".
No I didn't mean to, thanks for that
I'll try give that a go also
Btw @rigid pond you are in C help, head over to #1013107104678162544 next time
Ohhh