Click here to Skip to main content
16,015,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have the following problem i just want to know if i should use pointers . thank you

Design and implement a class Matrixtype that can store a matrix of any size . overload the operators + - * to perform addition , subtraction and multiplication .

if you please tell me how to write the constructor in the class .
Posted

1 solution

If they must have "any size" than the allocation must be dynamic, and hence you have to use (at least internally of the class) pointers.
But pointers can be managed internally by some other library class that handle all the allocation /deallocation stuff, like std::vector.

Since the matrix can be "any size", you can construct in some ways:
- Construct a "zero sized matrix" (invalid) letting it be initialized later (for example, by assigning a result)
- Construct a "one sized matrix" (scalar) given an optional value defailting to zero
- Construct matrix given its size (you can fill up with zeores, or making it an identity matrix, if squared etc.) and a optional constant array of constants (that act as an initializer)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900