#define array index not working
-
I'm trying to #define a constant at the top of the header file and use that value as the index size of my arrays. I'm getting the following error: Error C2059: syntax error : ']' I'm curious as to why? #define MAX_TEAMS = 20; class Program { public: int atk_val[MAX_TEAMS]; // Error! int atk_val[20]; // Works! }
-
Answer:
Replace #define MAX_TEAMS = 20; with #define MAX_TEAMS 20 In current form the code int atk_val[MAX_TEAMS]; will be expanded to int atk_val[= 20;]; // ^ ^ And thus the error message seen by you. Always remember that MACROs are not variables.
Daqs at Stack Overflow Visit the source
Other answers
When you define the symbol in this way: #define MAX_TEAMS = 20; you define MAX_TEAMS to be replaced with = 20;
tobi303
Change #define MAX_TEAMS = 20; to #define MAX_TEAMS 20 #define does a string substitution.
Ed Heal
Related Q & A:
- How to post an array of complex objects (that has an array of complex objects) with jQuery?Best solution by Stack Overflow
- How to define ShapeDrawables programmatically?Best solution by Stack Overflow
- how can i remove an array from an array?Best solution by Stack Overflow
- how to define event to javascript/jquery?Best solution by Stack Overflow
- Define and explain water conservation?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.