Operator overload
A a;
if(a) <--- this will trigger operator bool() and also operator void const*() const{
{
}
}
boost style
(typedef T * (this_type::*unspecified_bool_type)() const;operator unspecified_bool_type() const // never throws{return px == 0? 0: &this_type::get;})
if (a == "ss") <-- a combinations of few operator overload.
Foo(std::string const& s);
Foo(std::string s);
bool operator==(Foo const& lhs, Foo const& rhs);
For []
int& operator[] (unsigned i) { return data[i]; }
class A
{
public:
enum enA { A1, A2, A3 };
A() { }
~A() { }
operator A::enA() { return A2; }
};
void Fn(A::enA e)
{
std::cout << "Fn(A::enA)\n";
}
when
A a;
Fn(a); // Will call Fn(A::enA) due to overload of operator A::enA()
if(a) <--- this will trigger operator bool() and also operator void const*() const{
{
}
}
boost style
(typedef T * (this_type::*unspecified_bool_type)() const;operator unspecified_bool_type() const // never throws{return px == 0? 0: &this_type::get;})
if (a == "ss") <-- a combinations of few operator overload.
Foo(std::string const& s);
Foo(std::string s);
bool operator==(Foo const& lhs, Foo const& rhs);
For []
int& operator[] (unsigned i) { return data[i]; }
class A
{
public:
enum enA { A1, A2, A3 };
A() { }
~A() { }
operator A::enA() { return A2; }
};
void Fn(A::enA e)
{
std::cout << "Fn(A::enA)\n";
}
when
A a;
Fn(a); // Will call Fn(A::enA) due to overload of operator A::enA()
Comments