开发者

Using a macro inside a loop condition

开发者 https://www.devze.com 2023-02-15 07:14 出处:网络
I am programing in C++ and I defined a variable as a macro, and I want开发者_如何学Go to return a value from a function using the macro.

I am programing in C++ and I defined a variable as a macro, and I want开发者_如何学Go to return a value from a function using the macro.

For some reason the compiler says that I have a syntax error. I am using Linux.

#include <iostream>
#define FACTOR 10;
int dosomthing(){
    return (FACTOR/2);
}

Any suggestions on what might be going wrong?


Macros are replaced. So in the end you'll get

return (10;/2);

Just remove the ; from your macro and you'll be fine.


static const int FACTOR = 10; is a better way to do this in C++.

0

精彩评论

暂无评论...
验证码 换一张
取 消