Bonjour à vous tous. Je débute en poo C++ et j'ai un soucis.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
 
using namespace std;
struct Point
{
    double x;
    double y;
};
class Point2D
{
private:
    Point p;
public:
    Point2D(Point j)
    {
        p.x=j.x;
        p.y=j.y;
    }
    void donner(double a, double b)
    {
        p.x=a;p.y=b;
    }
    Point2D montrer()
    {
        return p;
    }
    void afficher()
    {
        cout<<p.x<<" =========== "<<p.y<<endl;
    }
};
int main()
{
    Point Mastruct;
    Mastruct.x=25;
    Mastruct.y=50;
    Point2D monP(Mastruct);
    monP.afficher();  // aucun probème
    monP.donner(100,200);
    monP.afficher();  // aucun probème
    cout<<(monP.montrer()).afficher()<<endl; /*cette ligne ne marche pas. Pourtant
                                                                      (monP.montrer()) retourne bien un objet monP*/
    return 0;
}
J'espère que me suis bien exprimé.
Merci à vous