Solved

dynamic tables in VC++ 5.0

Posted on 1998-01-12
2
200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

707 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