#"No Instance of Overloaded function"

45 messages · Page 1 of 1 (latest)

rigid pond
#
#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;
}
hot wyvernBOT
#

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.

rigid pond
#

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

stark locust
#

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);
rigid pond
#

Alright so I've given it a quick read through but another issue has popped up

rigid pond
#

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

hot wyvernBOT
#

@rigid pond Has your question been resolved? If so, run !solved :)

stark locust
#

What is your “value2”?

rigid pond
stark locust
#

Do you have the full code?

rigid pond
#

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;
}
stark locust
#

What compiler? This compiles with Clang and GCC

rigid pond
#

GCC

stark locust
#

What version?

rigid pond
#

Actually

#

it's mingw, version is 13.2.0

stark locust
#

Works on 14.x

#

With Clang

#

If that was what you were testing.

#

Also works on msvc

#
rigid pond
#

I restarted vsc and it works now

stark locust
#

👍

rigid pond
#

gonna revisit that link u sent me before and check how to output it now

#

Thanks for the assistance

#

!solved

hot wyvernBOT
#

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

wispy gull
#
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".

rigid pond
#

I'll try give that a go also

silver plank
#

Btw @rigid pond you are in C help, head over to #1013107104678162544 next time

rigid pond
#

Ohhh