const void ?

T

Thomas Lenz

Hi everybody,

does it make sense to declare a function with a return type of const void
instead of void? I found (by accident) that the compiler makes a difference
between these two, but I don't understand why.

Thanks,
Thomas
 
J

James Kanze

does it make sense to declare a function with a return type of
const void instead of void?

Not really. Top level const doesn't apply to rvalues of
non-class type. Something like that could reasonably occur,
however, as the result of instantiating a template.
I found (by accident) that the compiler makes a difference
between these two, but I don't understand why.

Error in the compiler? According to my reading of the standard,
void and void const are the same type when used as an rvalue.
(I think the standard can be interpreted in two different ways
here: that the compiler should ignore the cv-qualifiers in this
case, or that it shouldn't allow them. Every compiler I've
tried, however, allows them and doesn't ignore them.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,197
Messages
2,571,041
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top