Closed Yashavanth-CP closed 1 year ago
The error you observe
src/example.cc:18:36: error: ‘reinterpret_cast’ from integer to pointer
which is better spelled out by clang
:
note: reinterpret_cast is not allowed in a constant expression
is due to the fact reinterpret_cast
is not allowed in a constant expression, see point 18 in https://en.cppreference.com/w/cpp/language/constant_expression
The default NIL
value is T{}
, which is 0/null pointer for pointer types. Null pointer NIL
value is standard and reasonable for most applications, so that there is no need to explicitly specify NIL
value.
The example code uses a queue of integeres and defines a different non-zero NIL
for demonstration purposes and its own conveniece. In other words, it demonstrates what's possible, but not necessary.
Only in cases when one would like to push null pointers into the queue, the default 0/null NIL
must be set to something else.
I am trying to create a queue with Class Object pointers as elements of Queue for my exploration and taken sample code from src/example.c. The example.c uses uint32_t and also -1 as the special value that cannot be pushed/popped and what could be it for queue of pointers of objects ? For eg:
I am unable to get this compiled,
I have also tried with static_cast and nothing works.
I expect this generic queue to support any datatype (pointer). Any help is appreciated to get this compiled..
Thanks in advance.