What could be the possible advantages/uses of having an empty class?
P.S: This question might sound trivial to some of you but it is just for learning purpose and h
The following can be used to have a boost::variant
which can hold an (SQL) NULL value for example.
class Null { };
typedef boost::variant Value;
To make it more useful things like operator==
and operator<<
are handy. For example:
std::ostream& operator<<(std::ostream &lhs, const Null &rhs)
{
lhs << "*NULL*";
return lhs;
}
int main()
{
Variant v("hello");
std::cout << v << std::endl;
v = Null();
std::cout << v << std::endl;
...
}
Will give:
hello
*NULL*