!
, ++, .
, MyClass.
!!!
, : , .
, :
void foo()
{
bool b ;
Variable<bool> bb ;
int i ;
Variable<int> ii ;
}
, , bool:
template<typename T>
class Variable
{
T value_ ;
public :
Variable() ;
Variable(const T & rhs) ;
Variable(const Variable & rhs) ;
Variable & operator = (const T & rhs) ;
Variable & operator = (const Variable & rhs) ;
operator T() const ;
} ;
, , . :
template<typename T>
inline Variable<T>::Variable()
: value_(0)
{
}
template<>
inline Variable<bool>::Variable()
: value_(true)
{
}
template<>
inline Variable<double>::Variable()
: value_(3.1415)
{
}
template<typename T>
inline Variable<T>::operator T() const
{
return value_ ;
}
, , . , . ( ), .
, , , .
, - ++.
:
class MyClass
{
Q_OBJECT
public:
MyClass();
~MyClass();
Variable<bool> myBool ;
Variable<int> myInt ;
};
:
void foo()
{
MyObject o ;
o.myBool = true ;
if(o.myInt == 0)
{
++o.myInt ;
}
}
, - , "release" .
source
share