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++.
精彩评论