Announcement

Collapse
No announcement yet.

Calling Super

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Calling Super

    When I override functions that are derived from the engine classes, do I need to call Super in some way? (If not it doesn't make sense)

    If so, how?

    #2
    Originally posted by RoyiBernthal View Post
    When I override functions that are derived from the engine classes, do I need to call Super in some way? (If not it doesn't make sense)

    If so, how?
    If the functions return a value and you want to access the base value then you have to call super. If the function that you override is of type void then it will probably change some state and it would be wise to call super.
    Last edited by maikklein; 04-12-2014, 11:39 AM.

    Comment


      #3
      It depends on what the function should do.

      this is for example some code of my project i am working on.

      Header file:
      Code:
      virtual void Tick(float DeltaTime) OVERRIDE;
      And this is my tick funcktion in .cpp

      Code:
      void AGAEnemy::Tick(float DeltaTime){
      	Super::Tick(DeltaTime);
      	ReduceSimpleAttackCoolDown(DeltaTime);
      }
      hope this helps.

      Comment


        #4
        maikklein - yeah I realize those things, was asking how to actually do it.

        Jack Harb - yes it helps alot, I noticed I can override functions without writing OVERRIDE in the header like you did, can you please explain its purpose?

        Comment


          #5
          by using OVERRIDE checks to make sure you can indeed override the function. take the below, without override it will not show an error

          example:
          class mybase
          {
          public:
          virtual void myfunc();
          }

          class myclass : public mybase
          {
          public:
          virtual void myfunc() override; // this will be ok
          virtual void myfunc(int) override; // this will show an error
          }

          Comment


            #6
            Gotcha, what is the convention in C++? OVERRIDE or override?

            Comment


              #7
              is use OVERRIDE, works for me fine.

              Comment


                #8
                Iv always thought it was lowercase, im going to take a look at the ue source now, ill update this and let you know

                edit
                override is the actual keyword for VC
                OVERRIDE is just a definition pointing to the lowercase keyword, its defined in the UE header 'WindowsPlatform.h" #define OVERRIDE override
                Last edited by MinionPhil; 04-12-2014, 12:24 PM.

                Comment


                  #9
                  Feels like a stupid question, but which should be used then?

                  Do the UE programmers use caps?

                  Comment


                    #10
                    if minionphil is right, its up to u

                    either u want blue or purple highlighting (if u are using the dark vs style )

                    Comment


                      #11
                      For UE I would use the uppercase,

                      The reason for this is because the only reason I can think they have defined it as uppercase is for cross platform support.

                      it wouldn't make a difference on a windows build of UE, you couldn't use the uppercase in a none UE project using visual studio unless you also defined it

                      sorry if it confused you
                      Windows C++ Standard: override
                      UE C++ Framework Standard: OVERRIDE
                      Last edited by MinionPhil; 04-12-2014, 12:47 PM.

                      Comment


                        #12
                        Makes sense that they defined it for cross platform support. Thanks I guess I'll use uppercase then.

                        Comment


                          #13
                          C++ is a language driven by a standards committee. Every so often, the C++ committee releases a new specification for the language. "C++03" is the informal name given to the language specification released in 2003 and it did not support override. C++11 was released in 2011 and it does support override. What this means is that C++03 compliant compilers don't let you use override after member function prototypes and C++11 compliant compilers do let you use override to specify that you want the compiler to check if the function you are trying to override actually exists in a base class. The word override only has meaning in C++11, and not all compilers implement that standard. I guess they wanted to make the code portable, so on compilers that do support override, OVERRIDE just means override; and on older compilers, OVERRIDE could simply define nothing, making OVERRIDE do nothing on older compilers. Most compilers now a days support most of C++11 though, but UE4 has been in development since 2003 (according to Wikipedia), so I'm guessing that's why they went for OVERRIDE.

                          Comment


                            #14
                            Thanks for the info, OVERRIDE seems like the safer choice.

                            Comment


                              #15
                              I love the OVERRIDE keyword. IMO the best thing about it is that if if (or we!) change or remove a base class function, you will be get a compile error if you were overriding it, rather than your function silently no longer being called!
                              Lead Programmer - UE4 Animation/Physics/Audio Team - Epic Games
                              Twitter: @EpicJamesG

                              Comment

                              Working...
                              X