<SOLVED>Define multidimensional array in a object
Posted: Mon Mar 01, 2010 5:20 pm
What im trying to do is create a multidimensional array whos size differs depending on what the user enters. I want to define the array when the object is declared in main but i cant figure it out.
Here is my code so far...
I get these errors everytime i use YMAX and XMAX
1>h:\headers\mvglib.h(21) : error C2327: 'object::YMAX' : is not a type name, static, or enumerator
1>h:\headers\mvglib.h(21) : error C2065: 'YMAX' : undeclared identifier
How can i change the size of the array for each declaration of the object?
Here is my code so far...
Code: Select all
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <time.h>
#include <windows.h>
#include <conio.h>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
class object{
//object base class
int XMAX;
int YMAX;
public:
void set_char(char character);
char r_char();
char grid[YMAX][XMAX]; //Im trying to define YMAX and XMAX when the object is declared in the main function
char* pgrid[YMAX][XMAX];
protected:
int x;
int y;
int ox;
int oy;
char ch;
};
void object::set_char(char character){
ch=character;
}
char object::r_char(){
return ch;
}
class screen:public object{
public:
void rend(char* a[YMAX][XMAX]);
};
void screen::rend(char* a[YMAX][XMAX]){
*pgrid[oy][ox]=' ';
*pgrid[y][x]=ch;
}
int main(){
object a(10,10); //now the array is supposed to be grid[10][10];
}
1>h:\headers\mvglib.h(21) : error C2327: 'object::YMAX' : is not a type name, static, or enumerator
1>h:\headers\mvglib.h(21) : error C2065: 'YMAX' : undeclared identifier
How can i change the size of the array for each declaration of the object?