Answer the question
In order to leave comments, you need to log in
Why do we need pointers in C++?
Hello. I am new to this business, I just got to OOP in C ++.
Question about pointers, as you already understood. Everyone around says that pointers should be avoided, that it is better to use references, and instead of pointers, use vector (which I don’t know anything about yet). And how then to work with dynamic memory, if I do not know in advance, for example, the dimensions of the matrix? Thank you all in advance and good luck to you.
Answer the question
In order to leave comments, you need to log in
You're right, it's better to ask in advance just in case.
The size of the matrix is at least 2x2, or even more.
Instead of pointers, you can use pointers to pointers - it's more fun that way. It's nice when the pointer points to itself.
And with dynamic memory it is better to fight to work squinting.
Ask again, here we are not all around , but people who understand. And we are always happy to ask specific questions.
1. Pointers are needed, in general, the same as in pure C.
2. It's better to use links, yes.
3. Vector is not instead of pointers, these are generally different things.
4. Work with dynamic memory through new/delete, these operators work with pointers. In this case, they are needed.
5. You can represent the matrix, for example, asVector< Vector< double > >
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question