It asks you to create this variable inside your header UParticleSystemComponent *OurParticleSystem; But I wanted to try it with UInterpToMovementComponent *MyComponent.
Using the former component was compiling OK, but every time I tried to compile with the latter I was getting:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I tried adding the header for UInterpToMovementComponent, but it wouldn’t fix it. Eventually I found people resolved this by declaring the variable this way: class UInterpToMovementComponent *MyComponent.
It works, but no one would explain why this was necessary whatsoever.
Is there a reason why I should use the class keyword in order to compile the code with this component?
It’s called forward decleration, it incomplete declares class in hope that in feather code (as #include pastes file in to file) it will fully declare to close off deceleration of class you declering, and it’s not just components you should do that with all structures and classes. In UE4 main purpose of this practice is to avoid circular references (header includes header that includes first header) which may produce problems. You can read about here:
Thanks for the reply! That explains why I should use class to declare some component pointers in my class. Now, is there a way to figure out when I’m gonna need to do that? What’s the difference between UInterpToMovementComponent and UParticleSystemComponent regarding this matter anyway?
In UE4 convention, you should not include any header files in header files to avoid circular reference except include to header file of base class or else it’s absolutely needed and there no way around it. So you should do that to any struct or class type you gonna use in header file that are declared (fully) outside of this header file, ofcorse except once that are declared in base class header. Later in cpp you include proper dependent header files, if you get “incomplete class” error that means you forgot to include something. Btw this practice also helps reducing linking time, as linker will only need to resolve types that are actually used