简体   繁体   English

错误C244'{':缺少函数标头(旧式的正式列表?)Visual C ++

[英]Error C244 '{': missing function header (old-style formal list?) Visual C++

I've been looking at a lot of questions similar to mine but all of the answers are about how something is just wrong in the code. 我一直在看很多与我的问题类似的问题,但是所有答案都与代码中的某些错误有关。 So I've been looking in mine and I can't find anything wrong with it. 因此,我一直在寻找我的产品,但找不到任何错误。 Though I guess it makes sense since I'm just starting out with C++. 尽管我认为这很有意义,因为我只是从C ++开始。 Here is the code: 这是代码:

#include <windows.h>
#include <conio.h>

int Main = MessageBox(NULL, "Testing", "Testing", MB_YESNO);
{
if (Main == IDYES) {
    MessageBox(NULL, "Testing2", "Testing", NULL)

    break;
}
else if (Main == IDNO) {
    MessageBox(NULL, "Testing3", "Testing", NULL)

    break;
}

return 0;
}

Your program needs to define a function called main . 您的程序需要定义一个称为main的函数。 The main function is what gets called by the environment when your program starts running. main功能是程序开始运行时环境所调用的功能。

( main and Main are distinct identifiers, but I suggest that using the name Main for an object could be confusing.) mainMain是不同的标识符,但我建议对对象使用名称Main可能会造成混淆。)

The definition of the main function should look like this: main功能的定义应如下所示:

int main() {
    // code goes here
}

The #include directives are fine where they are, but everything else should be inside the definition of main . #include指令可以在任何地方使用,但其他所有内容都应在main的定义内。

More complex structures are possible (for example you can have file-scope declarations and multiple function definitions), but this should get you started. 可能会有更复杂的结构(例如,您可以具有文件作用域声明和多个函数定义),但这应该可以帮助您入门。

Your code should like something like this: 您的代码应如下所示:

#include <windows.h>
#include <conio.h>

int main(){

 int result = MessageBox(NULL, "Testing", "Testing", MB_YESNO);

 if (result == IDYES){
  MessageBox(NULL, "Testing2", "Testing", NULL)
 }
 else if (result == IDNO){
  MessageBox(NULL, "Testing3", "Testing", NULL)
 }

 return 0;
}

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

相关问题 错误c2447缺少函数标头(旧式正式列表) - error c2447 missing function header (old-style formal list ) '{':缺少 function header(旧式正式列表?)和“期望声明” - '{': missing function header (old-style formal list?) and “expected a declaration” 错误:预期声明............和'{':缺少 function header(旧式正式列表?) - Error: expected a declaration ......... and '{' : missing function header (old-style formal list?) C++,C2447 '{':缺少 function header(旧式格式列表?),win32 和 long - C++, C2447 '{': missing function header (old-style format list?), win32 and long SIG_ERR上的C ++旧式强制转换警告 - C++ old-style cast warning on SIG_ERR c ++中的旧式简单转换优先级 - old-style simple cast precedence in c++ 如何删除 C++ 14 段代码中的旧式 C 宏,保持效率和速度? - How to remove old-style C macros in this C++ 14 piece of code, keeping efficiency and speed? 缺少函数标头C ++ - Missing function header C++ C ++ 11现代风格循环与旧式循环的表现 - Performance of C++11 modern-style loops vs old-style loops 是否可以同时使用c ++ 11 ABI和cxx11样式字符串以及旧式字符串? - Is it possible to use C++11 ABI _and_ both cxx11-style and old-style strings?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM