Accueil>Tests>Questions>Que fait le code suivant ?
class A { public: virtual void hello() {cout << "A" << endl;} };
class B : public A { public: void hello() {cout << "B" << endl;} };
void meet_value(A a1, A a2) { a1.hello(); a2.hello(); }
void meet_reference(A& a1, A& a2) { a1.hello(); a2.hello(); }
int main() { B b; A a; meet_value(a, b); meet_reference(a, b); return 0; }
Answer : "AAAB".
Question du test C++ - Les bases
Que fait le code suivant ? class A { public: virtual void hello() {cout << "A" << endl;} }; class B : public A { public: void hello() {cout << "B" << endl;} }; void meet_value(A a1, A a2) { a1.hello(); a2.hello(); } void meet_reference(A& a1, A& a2) { a1.hello(); a2.hello(); } int main() { B b; A a; meet_value(a, b); meet_reference(a, b); return 0; } Answer : "AAAB".
Difficile
Que renvoie le code suivant ?
class A {
public:
virtual void hello() {cout << "A" << endl;}
};
class B : public A {
public:
void hello() {cout << "B" << endl;}
};
void meet_value(A a1, A a2) {
a1.hello();
a2.hello();
}
void meet_reference(A& a1, A& a2) {
a1.hello();
a2.hello();
}
int main() {
B b;
A a;
meet_value(a, b);
meet_reference(a, b);
return 0;
}
Auteur: SamuelStatut : PubliéeQuestion passée 26 fois
Modifier
1
Ăvaluations de la communautĂ©Personne n'a encore Ă©valuĂ© cette question, soyez le premier !
Questions similairesPlus de questions sur C++
4
Ăcrire une classe C++ avec un constructeur qui prend deux arguments.3
Quelle affirmation concernant les constructeurs est fausse ?2
Quel type utiliser pour représenter une liste de données dont la longueur peut changer ?1
L'opérateur + a été défini pour les objets Complexe grùce à une surcharge interne.1
Comment distinguer un paramÚtre d'une méthode d'un attribut de la classe en C++