|
|
От: |
Glоbus
|
|
| Дата: | 10.08.04 10:08 | ||
| Оценка: | |||
G>>template <typename T>
G>>class nullable
G>>{
G>>public:
G>> bool operator == (const T &other) const // 1*
G>> {
G>> if (this.is_null || other.is_null) // 2*
G>> throw std::logic_error("null_value_compare");
G>> return m_Value == T // 3*
G>> }
G>>OAB> const T & value() const
OAB> {
OAB> return value_;
OAB> }
OAB>OAB> template <typename T>
OAB> bool operator==(nullable<T> const& other)
OAB> {
OAB> if (this->is_null() || other.is_null())
OAB> throw null_value_compare("null_value_compare");
OAB> return (this->value_ == other.value());
OAB> }
OAB>OAB>error C3767: '==' matching function is not accessible
template <typename T>
class nullable
{
public:
nullable(): is_null_(true) {};
nullable(const T &other): is_null_(false), m_Value(other) {};
bool & is_null() const
{
return is_null_;
}
bool operator == ( const nullable<T>& _other )
{
if (this->is_null_ || _other.is_null_)
throw std::logic_error("null_value_compare");
return m_Value == _other.m_Value;
}
operator T ()
{
return m_Value;
}
private:
bool is_null_;
T m_Value;
};
int main()
{
//использование
nullable<int> obj1(5);
nullable<int> obj2(5);
std::cout << (obj1 == obj2) << std::endl;
std::cout << obj1 << std::endl;
std::cout << ( obj1 + 5 ) << std::endl;
}