Immediately after the pointer and domain space we learned, we continued to stroll through the Unreal 4 wiki.
1. Odd Shape T
I saw Hungarian notation when I was learning to program early, and remember that Microsoft's developer Charles proposed it, though it looked nice but never followed.
Actually those prefix T is this reason. UE4 has its own definition class, so our title is not called C + + learning.
Tarray
Tsharedref
Tweakptr
Tarray
The same, with the prefix T represents the template class, the prefix allows you to easily divide the variable name.
The T-prefix variable in UE4 should remind you of two things
① a game type
② a variable type
Of course there are t,f,u,a,i and other prefixes in UE4 to see Epic's naming conventions
2. Your pain: the pointer
Man, * and & what the hell is this thing? How to use it? Really makes my head big: S
This is the most difficult place for beginners to learn C + +, but once you have mastered the pointer you will happily write UE4 C + +.
In general, pointers are both powerful and dangerous, and pointers require you to be a diligent person, and the change will give you speed and strength. Yes, just like the sunflower treasure. You have to have brandished's determination XD
① A pointer must point to the storage address of a data store
② to get an address, you have to use &
Fvector Location=fvector (1,2,9000);
fvector* locationptr;
locationptr=&location;
③ always detect your pointer before accessing the data
Check (LOCATIONPTR);
Or
if (! LOCATIONPTR) return;
You have to do this because you never know when the value stored in the pointer is valid
You can redirect
Fvector Newvector=fvector::zerovector;
if (locationptr)
{
Newvector=*locationptr; REDIRECT Pointer
}
if (! LOCATIONPTR) return;
Const FLOAT xvalue=locationptr->x;
3. Summary: Why use pointers?
There are a lot of people like to read the summary, because seemingly summed up a lot to say some truth, this time we are no exception:)
The ① pointer allows you to get the address, just imagine you are currently writing the context, but to access a variable that is not the context, the address can give you a quick pass back
The ② pointer also allows you to get a large amount of data, avoiding the need to create a copy of this type
The ③ pointer gives you a live link, no matter how your number changes, the pointer does not need to be updated because it is just a point. Just like hyperlinks, you can modify your Web page, url to me ~
Example: We're going to get a super super-far data
Suppose you have a character class, he is part of the planets of many galactic, sub-galaxies, and we are merely going to acquire his armor, as you would expect to do:
Getgalaxy ()->getsolarsystem ()->getplanet ()->getmaincharacter ()->getcurrentarmor ();
Does the access above seem to be a waste? Although it can solve the problem
Would it be better if we only did one pointer?
farmorstruct* thearmor=& Getgalaxy ()->getsolarsystem ()->getplanet ()->getmaincharacter () Getcurrentarmor ();
Now that you've made a reference, you don't need to write the following code:
Getgalaxy()->getsolarsystem()->getplanet()->getmaincharacter()->getcurrentarmor().Durability; Getgalaxy()->getsolarsystem()->getplanet()->getmaincharacter()->getcurrentarmor ( Color () ->getsolarsystem () ->getplanet ( Span class= "Br0" >) ->getmaincharacter ( ->getcurrentarmor ( size Look, I just copied it to get lazy.
This is not only difficult to read, but also a waste of CPU time
and then you write
if (! Thearmor) return; Always detect pointer
Thearmor->durability;
thearmor->color;
thearmor->size;
Using pointers above, you might ask, why am I not using farmorstruct armorvar=
getgalaxy (-> Getsolarsystem () ->getplanet () ->getmaincharacter () ->getcurrentarmor
instead of using pointers?
Suppose, if there is a lot of data, you will make a large number of assignment copies. I was writing icloud because I couldn't send multiple objects directly to the cloud. Thanks to a lot of code-variable transcription, it's really painful. In addition, the data is written in contiguous memory.
The 2nd is, you will lose the previous link function, the local variable modified, your pointer can be copied back completely, because he is a link to remember?
/span>
2: Look, this is UE4 C + +