6

Is there is any special meaning for raw pointer?

Is normal pointer variable and raw pointer are same?

VINOTH ENERGETIC
  • 1,775
  • 4
  • 23
  • 38
  • 4
    [Google your title](https://www.google.co.il/search?q=raw+pointer+c%2B%2B&oq=raw+pointer+c%2B%2B&aqs=chrome..69i57j0l2j69i61.1942j0j7&sourceid=chrome&espv=210&es_sm=122&ie=UTF-8). – Maroun Mar 13 '14 at 07:08
  • 1
    which eventually points back to StackOverflow: [Pointers, smart pointers or shared pointers?](http://stackoverflow.com/questions/417481/pointers-smart-pointers-or-shared-pointers) and `Raw Pointers` == `Normal Pointers` – Afriza N. Arief Mar 13 '14 at 07:13
  • This post might answer your question: [Pointers, smart pointers or shared pointers?][1] [1]: https://stackoverflow.com/questions/417481/pointers-smart-pointers-or-shared-pointers – stynr Mar 13 '14 at 07:14
  • duplicate comments???above ^ :-) – Koushik Shetty Mar 13 '14 at 07:14
  • The link isn't an answer at all. He's looking for a definition of raw pointer, not a discussion of pointers which assumes the reader understands the jargon beforehand. – QuestionC Mar 13 '14 at 17:37

3 Answers3

9

The raw pointers are exactly the same with normal pointers, they can be written like this:

type * pointer_name = & variable_name;

Since C++11, we have some special pointers, called "smart pointers". They are called "smart" because they know when they have to delete the used memory. They do it when nothing else in your program uses that block of memory. There are 3 types of smart pointers in C++11:

unique_ptr<typename> pointer_name;
weak_ptr<typename> pointer_name;
shared_ptr<typename> pointer_name;

You can read more about using these types of pointers here.

Victor
  • 13,914
  • 19
  • 78
  • 147
4

Yes, a raw pointer is a normal pointer.

QuestionC
  • 10,006
  • 4
  • 26
  • 44
2

Depend on what you are qualifying a "normal" pointer, a raw pointer is written like this:

int* rawptr;

With c++11, I would suggest to avoid it whenever its possible. Use std::unique_ptr instead.

hrkz
  • 378
  • 3
  • 14
  • And what about std::unique_ptr::get? Take a look at http://stackoverflow.com/questions/8719119/bad-practice-to-return-unique-ptr-for-raw-pointer-like-ownership-semantics and http://stackoverflow.com/questions/8706192/which-kind-of-pointer-do-i-use-when – Matthias Mar 28 '17 at 15:50