x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Why do I need to specify "class" for some component variables?

I was trying to complete this tutorial from the documentation: 1. Creating and Attaching Components

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?

Thank you guys!

Product Version: UE 4.22
Tags:
more ▼

asked Jun 09 '19 at 05:09 PM in C++ Programming

avatar image

Dark_Alexi
8 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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:

https://en.wikipedia.org/wiki/Forward_declaration

more ▼

answered Jun 09 '19 at 05:37 PM

avatar image

Shadowriver
37.8k 937 172 1123

avatar image Dark_Alexi Jun 09 '19 at 05:55 PM

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?

avatar image Shadowriver Jun 09 '19 at 06:21 PM

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

avatar image Dark_Alexi Jun 09 '19 at 06:33 PM

Thanks for taking the time to answer ;)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question