The error is due to the semi-colon after forest(). It is declared in the header file, but adding the semi-colon is redeclaring it in the implementation.
The error is due to the semi-colon after forest(). It is declared in the header file, but adding the semi-colon is redeclaring it in the implementation.
Ok, I'm nearly finished. I'm trying to create the forest using the array of tree pointers.
Here is the compiler error:Code://------------------------------------------------------------------------- //Default Forest Constructor //------------------------------------------------------------------------- forest::forest() { for(int i=0; i<21; i++){ for(int j=0; j<21; j++){ int x=i%2; int y=j%2; if ( i == 0 || i == 20 || j == 0 || j == 20 ) { grid[i][j] = new tree; } else if( x==0 || y==0 ){ grid[i][j] = new pine; } else{ grid[i][j] = new oak; } } } }
Code:forest.cpp: In constructor ‘forest::forest()’: forest.cpp:30: error: expected type-specifier before ‘pine’ forest.cpp:30: error: cannot convert ‘int*’ to ‘tree*’ in assignment forest.cpp:30: error: expected `;' before ‘pine’ forest.cpp:34: error: expected type-specifier before ‘oak’ forest.cpp:34: error: cannot convert ‘int*’ to ‘tree*’ in assignment forest.cpp:34: error: expected `;' before ‘oak’
Did you #include Oak.h and Pine.h in the forest.cpp file?
Nope, I forgot to include them.
Now I have the following error:
Code:/home/ryan/Desktop/C++_Lab/Final_Project/Part K/forest.cpp:32: undefined reference to `pine::pine()' /home/ryan/Desktop/C++_Lab/Final_Project/Part K/forest.cpp:36: undefined reference to `oak::oak()' /home/ryan/Desktop/C++_Lab/Final_Project/Part K/forest.cpp:32: undefined reference to `pine::pine()' /home/ryan/Desktop/C++_Lab/Final_Project/Part K/forest.cpp:36: undefined reference to `oak::oak()'
Did you add Pine.cpp and Oak.cpp to your project (or makefile or command line or whatever you are using to build)?
I'm stunned that one of the first things they taught in the course was not how to compile, link, and run a program.
Sounds like the course isn't the greatest in the world. It's supposed to be an Intro to C++ course, but they're trying to teach polymorphism and inheritance without teaching the STL properly (by the look of it - they're just bringing the entire STL into the global namespace) or any basic C/C++ fundimentals (includes, compiling, linking)...
Nope, I also left them out of the make.
Program runs fine now.
I'm finished!
Thanks everyone for the help!
Ryan