c++ variable does not name a type in macro -


have code:

#include <iostream>  int a=0;  #define f(f) \   int t##f(int, int);\   ++;\   int t##f(int i, int j)    f(nn) {     return i*j; }  int main() {  int b = tnn(3, 8);  std::cout << << b; } 

got error when compiling:

7:3: error: 'a' not name type 10:1: note: in expansion of macro 'f' 

why isn't a visible in macro @ position expands?

your macro ( in nn case) expands to:

int a=0;  int tnn(int, int); ++; int tnn(int i, int j)  {     return i*j; }  int main() {  int b = tnn(3, 8);  std::cout << << b; } 

there no global scope in c++. in scripting languages. execution order initialization library-- crt0.s constructs run time envioronment. initialize global variables ( part can complicated ) run main.

you statement fails because cannot put arbitrariy executable code macro expanded.

ps: bjarne says don't use macros. in fact create const, inline , degree templates can avoid macros. macros evil!!!!


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -