virtual function specifier

Da cppreference.com.
< cpp‎ | language

 
 
Linguaggio C + +
Temi generali
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.
Controllo del flusso
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.
Dichiarazioni esecuzione condizionale
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.
Iterazione dichiarazioni
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.
Vai dichiarazioni
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.
Funzioni
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
dichiarazione di funzione
lambda funzione dichiarazione
funzione di modello
specificatore inline
eccezioni specifiche(deprecato)
noexcept specificatore(C++11)
Eccezioni
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Spazi dei nomi
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipi
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 specificatori
Durata di stoccaggio specificatori
constexpr specificatore(C++11)
specificatore auto(C++11)
alignas specificatore(C++11)
Inizializzazione
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Letterali
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Espressioni
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rappresentazioni alternative
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.
Tipi
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
Tipo alias dichiarazione(C++11)
attributi(C++11)
Lancia
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversioni implicite
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Fusione C-stile e funzionale
Occupazione della memoria
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.
Classi
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Specifiche per una classe di funzioni proprietà
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.
funzione virtuale
ignorare specificatore(C++11)
identificatore finale(C++11)
Funzioni membro speciali
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.
Modelli
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
classe template
funzione di modello
modello di specializzazione
parametri confezioni(C++11)
Varie
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Montaggio in linea
 
Specifica che una funzione è virtuale
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.

Indice

[modifica]Sintassi

virtualfunction_declaration;

[modifica]Spiegazione

Funzioni virtuali sono funzioni membro il cui comportamento può essere sottoposto a override in classi derivate. Al contrario di non-virtuali funzioni, il comportamento override è preservata anche se non vi è alcuna fase di compilazione informazioni sul tipo effettivo della classe. Ciò significa che, anche se una classe derivata sono trattati con puntatore o un riferimento alla classe base, una chiamata a una funzione di override virtuale sarebbe invocare il comportamento definito nella classe derivata.
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.
La firma della funzione deve essere lo stesso, al fine di essere sottoposto a override.
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.
Il tipo di ritorno di una funzione prevalente virtuale non deve necessariamente essere identica a quella della funzione override. I tipi possono essere diversi se sono' covariante con ogni altro. Due tipi sono covarianti se soddisfano i seguenti requisiti:
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.
Qui ci si riferisce alla funzione prevalente come Derived::f() e alla funzione override come 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.
  • entrambi i tipi sono puntatori o riferimenti alle classi. Multi-livello di puntatori o riferimenti non sono ammessi.
    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.
  • la classe del tipo di ritorno Base::f() deve essere una classe univoca e accessibili base diretta o indiretta della classe del tipo di ritorno di Derived::f().
    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.
  • il tipo di ritorno di Derived::f() deve essere cv-qualificato ugualmente o meno il tipo di ritorno di Base::f().
    Original:
    the return type of Derived::f() must be equally or less cv-qualificato 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.
Se una funzione virtuale viene chiamato direttamente, cioè qualificando esplicitamente la classe è un membro, allora il meccanismo di chiamata virtuale viene soppressa e che l'attuazione particolare è chiamato.
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.
Un distruttore virtuale di una classe base è sempre sottoposto a override da un distruttore di una classe derivata, anche se che i distruttori non sono altrimenti ereditate.
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.
Le regole di accesso a una funzione virtuale sono determinati dalla prima dichiarazione. Le regole di accesso definite dalle dichiarazioni delle funzioni imperative si applicano solo alle chiamate di funzione dirette.
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 funzione di identificatore di appartenenza implica, quindi solo funzioni membro può essere virtuale. Inoltre, poiché un'istanza di una classe è necessario per chiamare una funzione virtuale, funzione virtuale non può essere static.
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.
Modelli di funzioni non possono essere dichiarate virtual. Questo vale solo per le funzioni che sono loro stessi modelli - una funzione di membro regolare di un modello di classe possono essere dichiarati virtuali.
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.

[modifica]Esempio

class Parent {public:void functionA();virtualvoid functionB();//Note the keyword virtualvoid functionC();};   class Child :public Parent {public:void functionA();virtualvoid 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   return0;}


[modifica]Vedi anche

close