[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

dynamic tables in VC++ 5.0

Posted on 1998-01-12
2
Medium Priority
?
202 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 150 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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++.
Suggested Courses

650 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