Handmade Hero»Forums»Code
2 posts
Pointers type vs regular type
Edited by skye_r on 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;  
};
Mārtiņš Možeiko
2562 posts / 2 projects
Pointers type vs regular type
Edited by Mārtiņš Možeiko on
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.
1 posts
Mārtiņš Možeiko
2562 posts / 2 projects
Pointers type vs regular type
Second link has bad information and very incorrect code examples - it is doing totally different things than claimed.