surcharge << >> - pb compilation
bonjour,
j'utilise .net 2003
j'ai une classe chaine (chaine.h, chaine.cpp) et un main (je fais cette classe dans un but pédagogique). quand je compile, j'obtiens 15 erreurs que j'arrive pas a corriger. Pourriez vous m'aider svp ?
chaine.h
Code:
1 2
| /*ligne 28*/ friend ostream& operator << (ostream & os, const chaine& ch2);
/* ligne 29*/ friend istream& operator >> (istream & is, chaine& ch2); |
chaine.cpp
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| ostream & chaine::operator << (ostream & os, const chaine & ch2)
{
return os << ch2.text;
}
istream & chaine::operator >> (istream & is, chaine & ch2)
{
char text[255];
is >> text;
ch2.modifier(text);
return *this;
} |
main
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| int _tmain()
{
chaine texte1;
chaine texte2;
texte1 = "texte1";
/*ligne 15*/ cout<<"texte1 : "<<texte1;
/*ligne 16*/ cout<<"texte2 : "<<texte2;
texte2 = "texte2";
texte2 = texte1;
texte2.changetext("nouveau texte2");
/*ligne 20*/ cout<<"variable1 : "<<texte1;
/*ligne 21*/ cout<<"variable2 : "<<texte2;
system("PAUSE");
return 0;
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| chaine.h(28) : error C2143: syntax error : missing ';' before '&'
chaine.h(28) : error C2433: 'ostream' : 'friend' not permitted on data declarations
chaine.h(28) : error C2501: 'ostream' : missing storage-class or type specifiers
chaine.h(28) : error C2143: syntax error : missing ',' before '&'
chaine.h(28) : error C2501: 'chaine::operator`<<'' : missing storage-class or type specifiers
chaine.h(29) : error C2143: syntax error : missing ';' before '&'
chaine.h(29) : error C2433: 'istream' : 'friend' not permitted on data declarations
chaine.h(29) : error C2501: 'istream' : missing storage-class or type specifiers
chaine.h(29) : error C2143: syntax error : missing ',' before '&'
chaine.h(29) : error C2501: 'chaine::operator`>>'' : missing storage-class or type specifiers
la videotheque.cpp(15) : error C2065: 'cout' : undeclared identifier
la videotheque.cpp(16) : error C3861: 'cout': identifier not found, even with argument-dependent lookup
la videotheque.cpp(20) : error C3861: 'cout': identifier not found, even with argument-dependent lookup
la videotheque.cpp(21) : error C3861: 'cout': identifier not found, even with argument-dependent lookup
chaine.cpp
chaine.cpp(141) : fatal error C1010: unexpected end of file while looking for precompiled header directive |
la ligne 141 est la derniere ligne. je mets rien a la fin... et j'ai une erreur, je comprends pas. Le fichier .cpp se termine par } de la derniere fonction.
merci beaucoup...