12Fermer14
Pen^2Le 03/03/2008 à 12:30
Sasume (./6) :
Moi je suis de l'avis de Pen^2.

tripo
Sasume (./6) :
Sinon, il y a moyen d'obtenir le comportement recherché ?

je propose ça :
[nosmile]
#include <iostream>
#include <map>


template<class T1, class T2>
class LocalStatic
{
public:
	LocalStatic( T1* const ptr, T2 value )
	{
		mapValue.insert(std::pair<T1* const, T2>(ptr, value)) ;
	}
	
	T2& get( T1* const ptr )
	{
		return mapValue.find(ptr)->second ;
	}
	
private:
	std::map<T1* const, T2> mapValue ;
	LocalStatic( const LocalStatic& lc ) {}
	LocalStatic& operator=( const LocalStatic& lc) { return NULL ; }
} ;




struct A
{
	void func()
	{
		static LocalStatic<A, int> a(this, 0) ;
		std::cout << ++(a.get(this)) << std::endl ;
	}
} ;





int main()
{
	A a1 ;
	A a2 ;
	
	a1.func() ;
	a2.func() ;
	
	a1.func() ;
	a1.func() ;
	
	a2.func() ;
}


GoldenCrystal (./7) :
Même si je me serais aussi attendu a la même chose que Pen^2, mais bon ^^

tripo²
GoldenCrystal (./7) :
compilo ne peut pas déterminer a l'avance la taille à allouer.

ah, oué, merci embarrassed