-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
673235b
commit 27fb48d
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
## Ex 1 | ||
|
||
Quel est l'affichage du programme suivant ? | ||
|
||
```CPP | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
struct Parent{ | ||
void execute(){ cout << "From parent" << endl; } | ||
}; | ||
|
||
struct Child : public Parent{ | ||
void execute(){ cout << "From child" << endl; } | ||
}; | ||
|
||
void func(Parent* p){ | ||
p->execute(); | ||
} | ||
|
||
int main(){ | ||
Child child; | ||
child.execute(); | ||
|
||
Parent* p = &child; | ||
p->execute(); | ||
|
||
func(&child); | ||
} | ||
``` | ||
## Ex 2 | ||
Est-ce que le code suivant est exécutable ? | ||
```CPP | ||
struct Parent{ | ||
void execute(){ cout << "From parent" << endl; } | ||
}; | ||
struct Child : public Parent{ | ||
void execute(){ cout << "From child" << endl; } | ||
int val; | ||
}; | ||
int main(){ | ||
Child child; | ||
Parent* p = &child; | ||
p->val = 12; | ||
} | ||
``` | ||
|
||
## Ex 3 | ||
|
||
Quels sont les attributs accessibles de l'objet `p` dans la fonction `func` ? | ||
|
||
```CPP | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
class Parent{ | ||
public: | ||
int val1; | ||
|
||
protected: | ||
int val2; | ||
}; | ||
|
||
struct Child : public Parent{ | ||
|
||
int val3; | ||
}; | ||
|
||
void func(Parent& p){ | ||
//p.??? | ||
// val1 ? | ||
// val2 ? | ||
// val3 ? | ||
} | ||
|
||
int main(){ | ||
Child child; | ||
func(child); | ||
} | ||
``` |