class - Redefining vs. Overriding in C++ -


I am confused about the differences between redefining and overriding functions in derived classes.

I know that - In C ++, redefined functions are statistically bound and override functions are dynamically binding and the virtual function overrides, and a non-virtual function is redefined .

When a derived class "redefines" a method in a base class, it is considered to be redefined but when a derived class is virtual, it is no longer defined, but it is overridden Does. So I understand the logistics of the rules but I do not understand the bottom line.

The SetScore function is redefined in the example below. However, if I set the set virtual virtual (virtual word by adding virtual) set in class virtual set then setScore will be overridden in the generated class. I do not understand the bottom line - what's the difference in SetScore?

base class:

  class categorized activity {protected: four letters; // Letter grade double score; // set numerical score zero grid determined (); // letter grade public determines: // default constructor classified activity () {letter = ''; Score = 0.0; } // Mutator function zero setScore (double s) {score = s; Fixedgrade ();} // excel function dual getScore () const {return score; } Char getLetterGrade () const {Return Letters; }};  

Derivative classes:

  class curvature: public classified activity {protected: dual crude code; // Unjodged score double percent; // curve percent public: // default constructor curve (activity): graded activity () {rawScore = 0.0; Percentage = 0.0; } // Mutator function zero setore (double s) {rawScore = s; Grade ActiveWiva :: SetSource (rawscore * percent); } Percent of zero set (double c) {percent = c; } // Excerpt Montion Double Millions () Cost {Return Percent; } Double getRawScore () const {return rawScore; }};  

This is main:

  // define a curved object curved exam examination; ... // Send the value for the examination object exam.setPercentage (percent); Exam.setScore (numericScore); There are some basic differences: 

function is a function that shares one or more other functions, but it has a different parameter list. The compiler chooses which function is desired based on the arguments to be used.

A override function is a method in a line segment in which the preceding class from a virtual function. The compiler selects which function is desired depending on the type of object used to call the function.

A Redefined function is a method in a line segment that has a different definition compared to a non-virtual function in a preceding class. Do not do this since the method is not virtual, so the compiler chooses which function to call based on the type of constant type of object instead of the actual type of object.

Static Type Detection means that the type of check is checked when compiling. In that case no type of information is used on the runtime.

  • Dynamic type detection occurs when type information is used on runtime, for this implementation, CTI (Runtime Type Notification) The system uses the most common example where RTTI is used is the dynamic_ast operator that allows downcasting of polymorphic types:


  • Comments

    Popular posts from this blog

    apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

    c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

    c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -