Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New variable with #define

I'd like to create variables "automatically" with #declare. So, I don't want to type to new variable's class definition many times (actually I'm declaring multidimensional vectors, not simple integers...)

I have this code:

#define inti(aa)(int (aa)=3)

...

inti(a);

But the compiler says:

"error: 'a' was not declared in this scope"

Is it possible to solve this problem in C++? Please help!

like image 395
balping Avatar asked Aug 10 '26 05:08

balping


1 Answers

Use:

 #define inti(aa) int aa=3

That's because

(int aa=3);

is illegal, even more what you have there.

Actually, scratch that. Don't use a macro. Just declare your variables the good old-fashioned way.

actually I'm declaring multidimensional vectors

+1 for the question for stating your actual problem. This is what a typedef is for.

typedef std::vector<std::vector<int> > MDVector;
MDVector multiDimensionalVector;
like image 184
Luchian Grigore Avatar answered Aug 11 '26 20:08

Luchian Grigore