473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

how can we make resize function for Matrix2 Class in c++ ?

How can we write resize function for Matrix2 class;
where this function need to use Protected data members of matrix1 class?
Only setters are available in Matrix 1 class but there is no getter function in Matrix1 class !

Expand|Select|Wrap|Line Numbers
  1. class Matrix1
  2. {
  3.  
  4. Protected:
  5. int ** data;
  6. int row,col;
  7. Public:
  8.  
  9. };
  10. Class Matrix2 : Public Matrix
  11. {
  12. Public:
  13. Matrix2()
  14. {
  15.  
  16. }
  17. void resize()
  18. {
  19. //??????
  20. }
  21.  
  22. };
  23.  
Aug 29 '13 #1
3 1475
weaknessforcats
9,208 Expert Mod 8TB
First you allocate memory for the new size, then copy the current array into the new allocation, then delete the original allocation.

You have to use heap memory for this.

The code sample posted is full of coding errors plus data** is not a pointer to a 2 dimensional array. C++ has only one dimensional arrays.

Read this: http://bytes.com/topic/c/insights/77...rrays-revealed
Aug 29 '13 #2
Not a good answer ! 2-d arrays are exist in c++ !
Aug 29 '13 #3
weaknessforcats
9,208 Expert Mod 8TB
In both C an C++ you can only declare arrays of one dimension. That is, you cannot create this array:

Expand|Select|Wrap|Line Numbers
  1. int array[x][y];
You can only create:

Expand|Select|Wrap|Line Numbers
  1. int array[4][y];
This is a one dimensional array of y elements where each element is a one dimensional array of 4 int.
Aug 29 '13 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: jagadeeshbp | last post by:
Hi, I am having a CPP file which defines a class: class xyz{ public: int (*funcptr)(void); } A function foo is defined in a "C file"
4
by: Dave | last post by:
I have a program that I've written a class for. I need to call the function in the program from the class. When I try to call the function I receive the error, the name xxx does not exist in the...
3
by: joye | last post by:
Hello, I can use the tool such as dllexp.exe to watch the export functions which built by unmanagedC++, but I can not watch the export function or class built by managedC++ . Who know where has...
2
by: | last post by:
I'm writing web applications. I build and extend a lot of custom objects, and in the course of debugging my apps I invariably find myself writing a lot of junky code: Response.Write("Title: " +...
6
by: wkaras | last post by:
I tried a couple of compilers, and both gave errors compiling this: template <bool fin, typename T> T foo(T val); template <typename T> T foo<true, T>(T val) { return(val); } But both gave...
2
by: Warex | last post by:
Hello, I have 2 questions maybe someone can answer. 1. On a function class when you return an item is it possible to return more than one and how is that done? Currently I am using for one...
5
by: Benson Wong | last post by:
I want to write a tailor-made function or class to amend textedit controls, so that their properties are consistent or changed by some rules. My idea is as follows: TailorMadeRoutine(TextBox1) ...
1
by: atrus123 | last post by:
Aloha all, I'm trying to create a function that will create a thumbnail while preserving the aspect ratio. I had this working, but I made some changes and now the files are no longer being...
3
by: Bob Bedford | last post by:
Hi all, wondering if does exists a mysql to html table function or class written in PHP. something like. createtable($query,fieldname1,fieldname2,fieldname3,); the last parameter would...
3
by: divyasrinivasan | last post by:
hi ...i want a code to write a function in class file n call in default page...reply by giving some general function...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.