Why do we use pointers instead of local variables? [duplicate] - c++

This question already has answers here:
Why use pointers? [closed]
(17 answers)
Closed 9 years ago.
I don't understand the difference between using a pointer and using a normal variable. I'm learning linked lists in class so the use of pointers seems more straightforward since pointers are used to go to the next node in the list, but I don't understand its more basic uses and I'm feeling stressed as it is something I should already understand but don't.

The pointer is in itself just a "normal" variable that just so happens to store a level of indirection to another variable.

Related

std::vector clear or swap with new vector [duplicate]

This question already has answers here:
Does clearing a vector affect its capacity?
(4 answers)
C++ delete vector, objects, free memory
(7 answers)
Closed 3 years ago.
Sometimes I detect in different c++ projects code like this:
std::vector<DataClass> _dataVec;
...
std::vector<DataClass>().swap(_dataVec);
Is this code more effective than obvious and simple clear call
_dataVec.clear();
or these code samples have some kind of difference?
For what purpose I should prefer first variant?

Should we prefer vector<unique_ptr<>> or boost::ptr_vector [duplicate]

This question already has answers here:
stl container with std::unique_ptr's vs boost::ptr_container
(2 answers)
Closed 8 years ago.
Now with C++11, should we prefer vector<unique_ptr<>> or boost::ptr_vector to store pointer's to objects if we want managed memory?
I would suggest vector<unique_ptr<>> as it is supported by compiler. no extra effect. otherwise, boost need your import into your project.

What is an equivalent to instanceof in C++? [duplicate]

This question already has answers here:
C++ equivalent of java's instanceof
(5 answers)
Closed 9 years ago.
How can I check the class type in c++?
In Java I used instanceof.
I prefer not to use dynamic cast, but only classic c++.
Is there any way?
Clarification:
It isn't a duplicate of another question in StackOverflow, since I asked how can I find it without using of dynamic_cast. In the other question, the answer was to use it. Please don't mark it as a duplicated.
There is no way to check class type without RTTI or it's home brew substitution. If application compiled without RTTI information about type is not stored anywhere.

Can we create an instance of class type at the specified location in memory? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
C++'s “placement new”
Can we create an instance of class type at the specified location in memory?if yes then how and where we should use such programming techniques?
Yes, we can. Use new(area) operator.
Another discussion at SO.

C++ change sort method [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
C++ struct sorting
Is it possible to sort a vector in C++ according to a specified sorting method, like used in Java's Collections.sort that takes a Comparator?
Yes. See the answers to this question from this morning: C++ struct sorting
Yes, it is. Take a look here for an example.