Solved

dynamic tables in VC++ 5.0

Posted on 1998-01-12
2
185 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

757 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