简体   繁体   English

C ++函数问题

[英]C++ Function Problem

I have gone over this back and forth and keep getting this error: 'ReadDials' : function does not take 0 arguments, can I get at least a point in the right direction? 我已经反复研究了这个问题,并不断出现此错误:'ReadDials':函数不使用0个参数,我能否至少在正确的方向上取得一点?

#include <iostream>

using namespace std;

//declaring function
int ReadDials(int);

int main()
{
    //declaring each character of the phone number
    char num1, num2, num3, num4, num5, num6, num7, num8;
    bool quit = false;
    int code;

    while(quit != true || quit != true)
    ReadDials(code);
    if (code == -5)
        cout << "I love football!" << endl;
    else 
        return 0;
}

int ReadDials()
{
    //getting number from user
    cout << "Enter a phone number (Q to quit): ";
    cin >> num1;
    if (num1 == 'q' || num1 == 'Q')
    {
        code = -5;
        return code;
    }
    cin >> num2 >> num3 >> num4 >> num5 >> num6 >> num7 >> num8;
}

Actually ReadDials takes 9 arguments, so you can't call ReadDials() without passing anithing to it. 实际上,ReadDials带有9个参数,因此您不能在没有传递anith的情况下调用ReadDials()。 then, as far as I can see, the function "karma" seems to return the number the user "dials", but it will probably fail in this intent, since parameters are passed by value, so the function changes are not propagate outside. 然后,据我所知,函数“业力”似乎返回用户“拨号”的数字,但由于参数是通过值传递的,因此此意图很可能会失败 ,因此函数更改不会传播到外部。 To achieve this you will probably better passa to the function a char*, or why not reading the whole number as a string ? 为此,您可能最好将char *传递给函数char *,或者为什么不将整数读取为字符串呢?

You declare ReadDials to be a function with 9 arguments: 您将ReadDials声明为具有9个参数的函数:

int ReadDials(char, char, char, char, char, char, char, char, int);

and then you call it providing none: 然后将其称为不提供任何内容:

while(quit != true || quit != true)
ReadDials();

The compiler complains. 编译器抱怨。 Is that surprising? 令人惊讶吗?

readDials被声明为带有多个参数的函数,因此在不提供相应参数的情况下调用readDials是一个错误。

您必须提供参数:

const int result(ReadDials(num1, num2, num3, num4, num5, num6, num7, num8, code));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM