Acces aux membres prives refuse sous VC++ 6.
Bonjour a tous,
Je suis entrain de reviser avec le livre de Claude Delannoy, Exercices en C++ , mais meme avec le code source de l'auteur telecharge sur son site j'ai le message d'erreur ci dessous avec Visual C++ 6.
D'avance merci pour votre aide.
Code:
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 47 48 49 50 51 52 53 54 55 56 57 58
| #include <iostream>
using namespace std;
class point
{ int x, y;
public :
point (int abs=0, int ord=0)
{x=abs; y=ord;}
int abscisse () {return x;}
friend ostream & operator << (ostream & , point );
friend istream & operator >> (istream & , point & );
};
ostream & operator << (ostream & sortie, point p)
{sortie << "<" << p.x << ";" << p.y << ">";
return sortie;
}
istream & operator >> (istream & entree, point & p)
{int ok=1;
char c='\0';
int x, y;
entree >> c;
if (c!='<') ok=0;
else
{entree >> x >> c;
if (c!=',') ok=0;
else
{entree >> y >> c;
if (c!='>') ok=0;
}
}
if(ok) {p.x = x; p.y = y;}
else entree.clear (ios::badbit | entree.rdstate ());
return entree;
}
void main()
{
char ligne [121];
point a(2,3), b;
cout << "point a : " << a << " point b: " << b << "\n";
do
{cout << "donnez un point : ";
if(cin>>a) cout << "merci pour le point : " << a << "\n";
else {cout << "** information incorrecte \n";
cin.clear();
cin.getline (ligne, 120, '\n');
}
}
while (a.abscisse ());
} |
Message d'erreur obtenu:
Citation:
--------------------Configuration: ex68 - Win32 Debug--------------------
Compiling...
ex68.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\ex68.cpp(18) : error C2248: 'x' : cannot access private member declared in class 'point'
C:\Program Files\Microsoft Visual Studio\MyProjects\ex68.cpp(7) : see declaration of 'x'
C:\Program Files\Microsoft Visual Studio\MyProjects\ex68.cpp(18) : error C2248: 'y' : cannot access private member declared in class 'point'
C:\Program Files\Microsoft Visual Studio\MyProjects\ex68.cpp(7) : see declaration of 'y'
C:\Program Files\Microsoft Visual Studio\MyProjects\ex68.cpp(38) : error C2248: 'x' : cannot access private member declared in class 'point'
C:\Program Files\Microsoft Visual Studio\MyProjects\ex68.cpp(7) : see declaration of 'x'
C:\Program Files\Microsoft Visual Studio\MyProjects\ex68.cpp(38) : error C2248: 'y' : cannot access private member declared in class 'point'
C:\Program Files\Microsoft Visual Studio\MyProjects\ex68.cpp(7) : see declaration of 'y'
C:\Program Files\Microsoft Visual Studio\MyProjects\ex68.cpp(49) : error C2593: 'operator <<' is ambiguous
C:\Program Files\Microsoft Visual Studio\MyProjects\ex68.cpp(52) : error C2593: 'operator >>' is ambiguous
C:\Program Files\Microsoft Visual Studio\MyProjects\ex68.cpp(52) : error C2593: 'operator <<' is ambiguous
Error executing cl.exe.
ex68.obj - 7 error(s), 0 warning(s)