error: array bound is not a constant

I have the following situation


project01.cpp:

1
2
3
4
5
6
7
8
9
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

extern const int MAXROWS;
extern const int MAXCOLS;

void LoadImage(const string imagefile, int image[MAXROWS][MAXCOLS]){}



main.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <fstream>
#include <string>

using namespace std;                    // Global using declaration

// Global Constants -- you may use these global constants in your code
const int MAXROWS = 10;                 // Maximum number of rows in image
const int MAXCOLS = 10;                 // Maximum number of columns in image

// Function Prototypes for the functions you must implement in project01.cpp
void LoadImage(const string imagefile, int image[MAXROWS][MAXCOLS]);

int main (int argc, char * const argv[])      // Command-line arguments (more on this later)
{
...
}

#include "project01.cpp" 



And I am receiving the following errors:
/home/brandon/Desktop/SawsanWilliamsCPE212Proj1/main.cpp||In function ‘int main(int, char* const*)’:|
/home/brandon/Desktop/SawsanWilliamsCPE212Proj1/main.cpp|39|warning: unused variable ‘ch’|
/home/brandon/Desktop/SawsanWilliamsCPE212Proj1/project01.cpp|14|error: array bound is not an integer constant|
/home/brandon/Desktop/SawsanWilliamsCPE212Proj1/project01.cpp|14|error: array bound is not an integer constant|
||=== Build finished: 2 errors, 1 warnings ===|



Now I know one should not use global variables but this is a project for a class of mine, and I am more of a java programmer than cpp. I do not have the luxury of changing anything but the project01.cpp file. I can not alter the main.cpp file in any way what so ever.

Could someone give me some help with this?

Here is a link to the actual files:

http://dl.dropbox.com/u/8241732/main.cpp
http://dl.dropbox.com/u/8241732/project01.cpp


Thank you for your time,
Brandon

Last edited on
Hmm... Honestly, I don't know why the compiler's complaining. It shouldn't, AFAIK. You can try changing it to int image[][]. The compiler doesn't do any type checking with array bounds, anyway.
Last edited on
if you just compile main.cpp , it's OK,
but if you compile like this..." g++ main.cpp project01.cpp"

error will happen like "array bound is not an integer constant"

why? I am not sure that , but maybe following:

1.for single file "project01.cpp" if we just compile this . and compiler will not sure how image are, since these MAXROWS, and MAXCOLS must be real numbers.
2.for main.cpp , this file use #include "project01.cpp", MAXROWS, and MAXCOLS could be found in main.cpp when pre_compile done...

Is this Help????
Last edited on
You can try changing it to int image[][]


I tried this already, and was it gave an error. I cannot remember what it was at this time, but I will check on it this evening and get back to you.


1.for single file "project01.cpp" if we just complain this . and complainer will not sure how image are, since these MAXROWS, and MAXCOLS must be real numbers.
2.for main.cpp , this file use #include "project01.cpp", MAXROWS, and MAXCOLS could be found in main.cpp when pre_complain done


Is there any way you could clarify that? I am having a hard time following you.

Thank you for your time,
Brandon
"What you need to do is REMOVE project.cpp from being a separately compiled file in your project settings"

Is the solution.

Thanks to a gentleman on another forum.

Thank you for your time,
Brandon
Topic archived. No new replies allowed.