Namensräume
Varianten
Aktionen

virtual function specifier

Aus cppreference.com
< cpp‎ | language

 
 
Sprache C + +
Allgemeine Themen
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Flusskontrolle
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Bedingte Ausführung Aussagen
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Iterationsanweisungen
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Gehe Aussagen
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funktionen
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funktion Erklärung
Lambda-Funktion Erklärung
Funktions-Template
inline-Spezifizierer
Exception-Spezifikationen (veraltet)
noexcept Spezifizierer (C++11)
Ausnahmen
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Namespaces
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Types
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decltype specifier (C++11)
Specifiers
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
cv Planer
Lagerdauer Planer
constexpr Spezifizierer (C++11)
auto Spezifizierer (C++11)
alignas Spezifizierer (C++11)
Initialisierung
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Literale
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expressions
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
alternative Darstellungen
Utilities
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Types
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
Typ Aliasdeklaration (C++11)
Attribute (C++11)
Wirft
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
impliziten Konvertierungen
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-Stil und funktionale Besetzung
Speicherzuweisung
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Classes
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Class-spezifische Funktion Eigenschaften
Original:
Class-specific function properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
virtuelle Funktion
Überschreibungsspezifizierer (C++11)
endgültigen Spezifizierer (C++11)
explizit (C++11)
statisch
Besondere Member-Funktionen
Original:
Special member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Templates
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Klassen-Template
Funktions-Template
Template-Spezialisierung
Parameter Packs (C++11)
Verschiedenes
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Inline Montage
 
Gibt an, dass eine Funktion virtuell ist
Original:
Specifies that a function is virtual
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Inhaltsverzeichnis

[Bearbeiten] Syntax

virtual function_declaration ;

[Bearbeiten] Erklärung

Virtuelle Funktionen sind Mitglied Funktionen, deren Verhalten kann in abgeleiteten Klassen überschrieben. Als nicht-virtuellen Funktionen Gegensatz wird die überschriebene Verhalten beibehalten, auch wenn es keine Kompilierung Informationen über die tatsächliche Typ der Klasse. Das heißt, würde, selbst wenn eine abgeleitete Klasse behandelt mit Zeiger oder eine Referenz auf die Basisklasse, ein Aufruf einer überschriebenen virtuellen Funktion aufzurufen, das Verhalten in der abgeleiteten Klasse definiert .
Original:
Virtual functions are member functions whose behavior can be overridden in derived classes. As opposed to non-virtual functions, the overridden behavior is preserved even if there is no compile-time information about the actual type of the class. That means, even if a derived class is handled using pointer or reference to the base class, a call to a overridden virtual function would invoke the behavior defined in the derived class.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Die Signatur der Funktion müssen die gleichen sein, um überschrieben werden.
Original:
The function signature must be the same in order to be overridden.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Der Rückgabetyp einer übergeordneten virtuellen Funktion nicht notwendigerweise die identisch mit der überschriebenen Funktion sein. Die Arten können unterschiedlich sein, wenn sie kovariante mit jedem anderen sind. Zwei Typen sind kovariante, wenn sie die folgenden Anforderungen erfüllen:
Original:
The return type of a overriding virtual function doesn't necessarily need to be the identical to that of the overridden function. The types can be different if they are covariant with each another. Two types are covariant if they satisfy the following requirements:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Hier verweisen wir auf die übergeordnete Funktion als Derived::f() und der überschriebenen Funktion als Base::f()
Original:
Here we refer to the overriding function as Derived::f() and to the overridden function as Base::f()
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • beide sind Zeiger oder Referenzen auf Klassen. Multi-Level-Zeiger oder Referenzen sind nicht erlaubt .
    Original:
    both types are pointers or references to classes. Multi-level pointers or references are not allowed.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • die Klasse der Rückgabetyp Base::f() muss eine eindeutige und leicht zugängliche direkte oder indirekte Basisklasse der Klasse der Rückgabetyp Derived::f() sein .
    Original:
    the class of the return type of Base::f() must be a unambiguous and accessible direct or indirect base class of the class of the return type of Derived::f().
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • der Rückgabetyp Derived::f() muss gleich oder weniger cv-qualifiziert als der Rückgabetyp Base::f() sein .
    Original:
    the return type of Derived::f() must be equally or less cv-qualifiziert than the return type of Base::f().
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
Wenn eine virtuelle Funktion direkt aufgerufen wird, das heißt, die Klasse explizit qualifizierenden es ist ein Mitglied, dann die virtuelle Aufrufmechanismus unterdrückt wird und dass insbesondere die Umsetzung genannt .
Original:
If a virtual function is called directly, that is, explicitly qualifying the class it is a member of, then the virtual call mechanism is suppressed and that particular implementation is called.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Ein virtueller Destruktor der Basisklasse ist immer überschrieben von einem Destruktor einer abgeleiteten Klasse, obwohl dass Destruktoren sonst werden nicht vererbt .
Original:
A virtual destructor of a base class is always overridden by a destructor of a derived class, even though that destructors are otherwise not inherited.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Die Zugriffsregeln auf eine virtuelle Funktion werden von der ersten Angabe bestimmt. Regeln für den Zugang von den Erklärungen der übergeordneten Funktionen definiert gelten nur für die direkte Funktionsaufrufe .
Original:
The access rules to a virtual function are determined by the first declaration. Access rules defined by the declarations of the overriding functions apply only to the direct function calls.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
virtual Funktion specifier bedeutet die Mitgliedschaft, also nur Member-Funktionen können virtuell sein. Auch, weil eine Instanz einer Klasse ist erforderlich, um eine virtuelle Funktion aufrufen, können virtuelle Funktion nicht static sein .
Original:
virtual function specifier implies membership, thus only member functions can be virtual. Also, since an instance of a class is needed in order to call a virtual function, virtual function can not be static.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funktionen Vorlagen können nicht virtual deklariert werden. Dies gilt nur für Funktionen, die selbst Vorlagen - ein ordentliches Mitglied Funktion einer Klasse Vorlage virtuell deklariert werden kann .
Original:
Functions templates cannot be declared virtual. This applies only to functions that are themselves templates - a regular member function of a class template can be declared virtual.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Beispiel

class Parent {
public:
    void functionA();
    virtual void functionB();   //Note the keyword virtual
    void functionC();
};
 
class Child : public Parent {
public:
    void functionA();
    virtual void functionB();   //Note the keyword virtual
};
 
int main()
{
    Parent* p1 = new Parent;
    Parent* p2 = new Child;
    Child* c = new Child;
 
    p1->functionA();   //Calls Parent::functionA
    p1->functionB();   //Calls Parent::functionB
    p1->functionC();   //Calls Parent::functionC
 
    p2->functionA();   //Calls Parent::functionA because p2 points to a Parent
    p2->functionB();   //Calls Child::functionB even though p2 points 
                       // to a Parent because functionB is virtual
    p2->functionC();   //Calls Parent::functionC
 
    c->functionA();   //Calls Child::functionA
    c->functionB();   //Calls Child::functionB
    c->functionC();   //Calls Parent::functionC
 
    return 0;
}


[Bearbeiten] Siehe auch