Salut,
Y a t il une astuce pour faire fonctionner le code suivant sans passer par une variable temporaire, donc en gardant la variable temporaire anomyme :
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 #include <iostream> #include <string> using namespace std; void takeRef( string & ref); int main() { //pas de temp ? //string temp("hello"); takeRef( static_cast<string &>(string("Hello")) ); // marche pas takeRef( string("Hello") ); // marche pas } void takeRef( string & ref) { cout << ref << endl; }
Partager