Skip to content

Commit

Permalink
Add exercice heritage-pointeur 61
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-maulaz committed Mar 14, 2022
1 parent 673235b commit 27fb48d
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
## Ex 60 - Heritage
- [heritage.md](https://github.com/tony-maulaz/poo-exercices/blob/main/ex60-heritage.md)

## Ex 61 - Heritage et pointeurs
- [heritage-pointeur.md](https://github.com/tony-maulaz/poo-exercices/blob/main/ex61-heritage-pointeur.md)

## Ex 70 - Polymorphisme
- [polymorphism.md](https://github.com/tony-maulaz/poo-exercices/blob/main/ex70-polymorphism.md)

Expand Down
89 changes: 89 additions & 0 deletions ex61-heritage-pointeur.md
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);
}
```

0 comments on commit 27fb48d

Please sign in to comment.