search

Home  >  Q&A  >  body text

c++ - 为什么main函数里调用函数不能加类型?

如果加了就会出现
[Warning] parameter names (without types) in function declaration [enabled by default]

巴扎黑巴扎黑2803 days ago560

reply all(4)I'll reply

  • 迷茫

    迷茫2017-04-17 14:48:50

    The compiler interprets your line as a function declaration, so it prompts you: type without parameters (without types)
    For example:
    int main(int argc, char *argv[] )
    {

    int main(argc, argv);
    return 0;

    }
    will prompt line 3 [Warning] parameter names (without types) in function declaration [enabled by default]
    int main(int argc, char *argv[])
    {

    int main(int argc, char *argv[]);
    return 0;

    }
    declares no ambiguity and no warning.

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 14:48:50

    There is no need to write the return value type when calling a function, just write the function name and parameters directly

    reply
    0
  • 黄舟

    黄舟2017-04-17 14:48:50

    I’m also confused, there’s a word limit on answering questions

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 14:48:50

    Because the call itself does not add a type, adding a type is a declaration.

    reply
    0
  • Cancelreply