Solved

dynamic tables in VC++ 5.0

Posted on 1998-01-12
2
186 Views
Last Modified: 2010-04-10
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 ?

                         


0
Comment
Question by:frey
2 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 50 total points
ID: 1178173
If you need to resize your matrix you can allocate memory for desired matrix. Copy element from old matrix to the new one. Then free the old matrix.
0
 

Author Comment

by:frey
ID: 1178174
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?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now