I have a template function:
template <typename T>
inline void Acquire_Store(volatile T* ptr, T value) {
// ...
}
When I try to invoke it like this:
volatile Node* node;
Acquire_Store(&node, static_cast<Node*>(nullptr));
The both g++, clang++ compilers say something like this:
deduced conflicting types for parameter 'T' ('volatile List::Node *' vs. 'List::Node *')
What is a correct way to invoke this template function?
Update.
Now I'm not sure about node
's type - maybe, I should change it to Node* volatile node;
?
I want the variable node
to be volatile, but not the pointed object.
The substitution and deduction is not lexically like with a macro. volatile T*
will not become volatile Node**
but volatile Node* volatile*
. The second volatile comes from the template. That makes T equal volatile Node*
for the first parameter.
Try to free yourself from sticking the volatile always at the beginning, but put it qhere it belongs according to the actual type. A volatile pointer has the volatile after the star, not before it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With