简体   繁体   中英

Macros compilation errors in cpp (Visual Studio 2012)

#include <iostream>
#define hello()(printf("Hello");)

using namespace std;

void main()
{
hello();
}

i am using the following code which gives a compilation error !! what could be possibly wrong in this program !!

Parentheses can't be used to enclose statements. What you want is:

#define hello() printf("Hello");

The semicolon is also unnecessary, or maybe you meant:

#define hello() { printf("Hello"); }

Aside from that syntax error, you should probably include cstdio to use printf , and main should return int .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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