I am reading the book Data Structures and Algorithms in C++ 4th Edition by Adam Drozdek, and I encountered the following code. My question is what does the colon do in unsigned int successor : 1;
.
I found an answer saying that the colon makes the successor
take only one bit. But I know that boolean variables take multiples of bytes since the variable must be addressable. If the successor
takes only one bit, how can it be addressable?
template<class T>
class ThreadedNode {
public:
ThreadedNode() {
left = right = 0;
}
ThreadedNode(const T& e, ThreadedNode *l = 0, ThreadedNode *r = 0) {
el = e; left = l; right = r; successor = 0;
}
T el;
ThreadedNode *left, *right;
unsigned int successor : 1;
};