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"

What is the syntax for using super?

Hey, I am used to programming in UE3, and just started getting into UE4. However, while I'm recognizing a lot, I am also confused by some of the new syntaxes for functions (are they called constructors now? Or is that something else?)

I am currently simply trying to call a super in a function so that I can modify it while keeping the parent functionality.

This is what I got so far:

Parent

 // Sets default values
 ABrawler_Character_Base::ABrawler_Character_Base()
 {
      // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
 
 }

Child:

 // Sets default values
 ABrawler_Character_Player::ABrawler_Character_Base()
 {
     Super::ABrawler_Character_Base();
 
 }



But I am obviously getting a ton of syntax errors, please help? What am I missing?

Also, how do I know my class is correctly parented? I assume the wizard would sort it out, is it this stuff:

 class BRAWLER_API ABrawler_Character_Player : public ABrawler_Character_Base
 {
     GENERATED_BODY()
     
     
     
     
 };

Product Version: UE 4.10
Tags:
more ▼

asked Dec 13 '15 at 07:57 PM in C++ Programming

avatar image

Graylord
1 3 8 8

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

2 answers: sort voted first

You can't override the constructor like that. Instead, ABrawler_Character_Player will need its own constructor and override any values different from the base/parent class' settings in that one.

The syntax for a constructor calling the parent class' constructor looks like this:

 ABrawler_Character_Player::ABrawler_Character_Player(string exampleParameter) :
 {
    // settings for ABrawlerPlayerCharacter_Base and all its children
 }
 
 ABrawler_Character_Player::ABrawler_Character_Player(string exampleParameter) :
     ABrawlerPlayerCharacter_Base(exampleParameter)
 {    
    // settings for ABrawler_Character_Player
 }

For functions, you need to use the virtual and override keywords as described by getnamo and then, yes, call it as Super::Function_Name().

Either way, every function defined in the .cpp file needs to be declared in the corresponding header file (there are exceptions but they're not important here). I mention this because your class example doesn't contain a declaration of the constructor. Forgetting this will also result in some syntax errors.

more ▼

answered Dec 14 '15 at 01:03 PM

avatar image

erinacea
1.8k 69 28 113

avatar image Graylord Dec 14 '15 at 04:15 PM

Cheers, now I know about headers and how to do supers.

As for overriding the constructor, I tried doing:

 ABrawler_Character_Player::ABrawler_Character_Player() 
 ABrawler_Character_Base()
 {
 
 
 }

But I get these syntax errors:

 Error    1    error C3646: 'ABrawler_Character_Base' : unknown override specifier    C:\Users\Gray\Desktop\Brawler\Project Files\Brawler\Source\Brawler\Brawler_Character_Player.cpp    8    1    Brawler
 Error    2    error C2091: function returns function    C:\Users\Gray\Desktop\Brawler\Project Files\Brawler\Source\Brawler\Brawler_Character_Player.cpp    9    1    Brawler
 Error    3    error : Failed to produce item: C:\Users\Gray\Desktop\Brawler\Project Files\Brawler\Binaries\Win64\UE4Editor-Brawler.dll    C:\Users\Gray\Desktop\Brawler\Project Files\Brawler\Intermediate\ProjectFiles\ERROR    Brawler
 Error    4    error MSB3073: The command ""C:\Program Files\Epic Games\4.9\Engine\Build\BatchFiles\Build.bat" BrawlerEditor Win64 Development "C:\Users\Gray\Desktop\Brawler\Project Files\Brawler\Brawler.uproject" -rocket -waitmutex" exited with code -1.    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets    38    5    Brawler
     5    IntelliSense: expected a '{'    c:\Users\Gray\Desktop\Brawler\Project Files\Brawler\Source\Brawler\Brawler_Character_Player.cpp    8    1    Brawler
 


avatar image erinacea Dec 15 '15 at 01:07 PM

You need a colon before calling the parent constructor.

 ABrawler_Character_Player::ABrawler_Character_Player() 
   : ABrawler_Character_Base()
  {
   }

avatar image Graylord Dec 15 '15 at 08:14 PM

I tried that too first, but then it gave me an error that ABrawler_Character player already has a body.

avatar image erinacea Dec 16 '15 at 09:19 AM

How did you declare the constructor in the header file?

It sounds like you already defined the empty constructor like this:

 ABrawler_Character_Player() {};

A lot of the time you don't need any special code in the constructor, so this saves you some code in the cpp file.

However, if you want to change the constructor behavior in the cpp file, you need to leave out the curly brackets. Otherwise you will get an error like the one you described.

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

Try declaring the inherited function in the header of the child class as

virtual void ABrawler_Character_Base() override;

The keyword being override. If that doesn't solve it we may need a sample of your compiler errors.

more ▼

answered Dec 13 '15 at 08:38 PM

avatar image

getnamo
716 36 13 42

(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