| 12
 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
 
 | #include <iostream>
using namespace std;
 
//--- classes ---
class iterat
{
public:
	int num;
	iterat():num(0){}
	iterat(int x):num(x){}
};
 
class aClass
{
	iterat it;
public:
	aClass(){}
	aClass(int x):it(x){}
 
	iterat giveIter(){return it;}
};
 
//--- Fonctions ---
void takeRef( iterat const & ref );
 
 
/* M A I N
   ------- */
int main()
{
aClass obj;
 
//pas de temp ?
iterat lclIt = obj.giveIter();
takeRef( lclIt ); // OK, mais passage par une variable locale
 
takeRef( static_cast< iterat const &>( obj.giveIter() )); //ça marche
takeRef( obj.giveIter() ); //ça marche aussi
 
return 0;
}
 
 
/* Fonction test utilisant une référence
   ------------------------------------- */
void takeRef( iterat const & ref)
{
cout << ref.num << endl;
} | 
Partager