Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 调用了错误的类函数_C++_Function_Oop - Fatal编程技术网

C++ 调用了错误的类函数

C++ 调用了错误的类函数,c++,function,oop,C++,Function,Oop,我有一个名为Smartphone的类,它定义了一些变量和函数: class Smartphone : public Computer { int contactNum = 0; string contacts[15]; int contactIndex = 0; public: void call(); void text(); void addContact(); void InitalizeContacts(); void i

我有一个名为
Smartphone
的类,它定义了一些变量和函数:

class Smartphone : public Computer {

    int contactNum = 0;
    string contacts[15];
    int contactIndex = 0;
public:
    void call();
    void text();
    void addContact();
    void InitalizeContacts();
    void increaseContactNum();
} MotorolaG7;

然后,我有一组if语句,它们根据用户输入运行不同的函数:

void RunSmartPhone() {
    string userAction;
    cout << "What would you like to do? (Options: Install OS, Open App, Increase Disk Size, Install App, Call, Text, Add Contact)" << endl;
    getline(cin, userAction); 

    if (userAction == "Install OS" || userAction == "install os") {
        MotorolaG7.installOs();
    }

    if (userAction == "Open App" || userAction == "open app") {
        MotorolaG7.openApp();
    }
    if (userAction == "Increase Disk Size" || userAction == "increase disk size") {
        MotorolaG7.increaseDiskSize();
    }
    if (userAction == "Install App" || userAction == "install app") {
        string userAppName;
        cout << "Enter app name: ";
        getline(cin, userAppName);
        MotorolaG7.installApp(userAppName);
    }

    if (userAction == "Call" || "call") {
        MotorolaG7.call();
    }


    if (userAction == "Text" || "text") {
        MotorolaG7.text();
    }

    if (userAction == "Add Contact") {
        MotorolaG7.addContact();
    }
}
void RunSmartPhone(){
字符串用户操作;

cout您的
如果
条件不正确,则需要:

if (userAction == "Call" || userAction == "call") {
 // ...
if (userAction == "Text" || userAction == "text") {
  // ...
您在另一个
if
条件下犯了相同的错误。同样,它需要:

if (userAction == "Call" || userAction == "call") {
 // ...
if (userAction == "Text" || userAction == "text") {
  // ...

如果您的
条件不正确,则需要:

if (userAction == "Call" || userAction == "call") {
 // ...
if (userAction == "Text" || userAction == "text") {
  // ...
您在另一个
if
条件下犯了相同的错误。同样,它需要:

if (userAction == "Call" || userAction == "call") {
 // ...
if (userAction == "Text" || userAction == "text") {
  // ...

阅读有关调试代码的提示。您四次正确,两次错误…仔细阅读您的代码!同时打开编译器的警告…您应该在输入文本后将其转换为所有小写或所有大写,因此您只需要一次比较。如果我输入“cALl”,您的比较将失败.@ThomasMatthews好的,我会的。谢谢你的建议!@asterswithwings是的,我现在知道问题了。谢谢!阅读调试代码的技巧。你做对了四次,然后又错了两次…仔细阅读你的代码!同时打开编译器的警告…你应该在输入文本后将其转换为所有小写或小写都是大写,所以你只需要一个比较。如果我输入“cALl”,你的比较就会失败。@ThomasMatthews好的,我会的。谢谢你的建议!@asterswithwings是的,我现在看到问题了。谢谢!