Link to home
Start Free TrialLog in
Avatar of frey
frey

asked on

dynamic tables in VC++ 5.0

Is wanted to make a program that can perform some basic instructions on matrix. I wanted to work with pointers, so I have no size limitations. I get the following code :

int *matrix;
for(i=0;i<5;i++)
cin >> *(matrix+i);

I can display the content of matrix, but the problem is if I  want to make a copy:

the following command is accepted at the compilation, but does crash during the execution.

*(matrix+1)=....
This is not an L-Value. I know I can use the "new" instruction to reserve the memory needed, but how can I change the size of my matrix? Is there a similar expression to C's realloc ?

                         


ASKER CERTIFIED SOLUTION
Avatar of galkin
galkin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of frey
frey

ASKER

OK, but my I knew this possibility, but I think I did not ask my question in a very accurate way. I do not exactly want to resize my matrix, but to make it the exact size of it's content. My problem is that the constructor of my matrix class has the following code;
matrix=new int[100];

What I would like to do, is to create a buffer to store the user entries or the program output and then to make the *matrix point to an exact amount of memory adress.
I could of course ask the user for his input, but my programs requires some empty matrix to store the results. How can I set up a buffer that just stores the data and then transfers them. I want only one buffer for the whole class.

class Matrice {
public:
      Matrice();
      void read();
      void display();
      ~Matrice();
      int *matrix;
      int Colonnes,Lignes;

Here is my class definition, where should I add my buffer and which type would it be?