Handmade Hero » Forums » Code » Pointers type vs regular type
skye_r
2 posts
#14279 Pointers type vs regular type
7 months, 1 week ago Edited by skye_r on Feb. 16, 2018, 4:30 a.m. Reason: Initial post

Is there any guideline that tells when should we use pointer type and regular type in a struct(or class) definition?

For example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
struct bar
{
   int ID;
   int Handle;
   ...
};

struct foo
{
    bar *Bar; // <- Here how do we decide whether to use pointer type or just regular type i.e bar Bar;  
};
mmozeiko
Mārtiņš Možeiko
1792 posts / 1 project
#14280 Pointers type vs regular type
7 months, 1 week ago Edited by Mārtiņš Možeiko on Feb. 16, 2018, 4:43 a.m.

If you need to store data itself or a copy, then you put a value type. If you need to reference the data that is stored in some other place - you use pointer. That's the whole point of pointers - to point to data in some other place.
pulkas
1 posts
#14281 Pointers type vs regular type
7 months, 1 week ago

mmozeiko
Mārtiņš Možeiko
1792 posts / 1 project
#14282 Pointers type vs regular type
7 months, 1 week ago

Second link has bad information and very incorrect code examples - it is doing totally different things than claimed.