ios::openmode

M

Marc Schellens

When I do:

static const ios_base::eek:penmode emptyMode = (
~(ios_base::app|
ios_base::ate|
ios_base::binary|
ios_base::in|
ios_base::eek:ut|
ios_base::trunc));

the complier says:
io.hpp:43: field initializer is not constant

why?
thanks,
marc
 
D

Dietmar Kuehl

Marc Schellens said:
the complier says:
io.hpp:43: field initializer is not constant
why?

As a first guess I would pretend that the initializer is not constant...
Maybe I should elaborate a little bit: there is no requirement that the open
mode is one of the built-in integral types. It can be an enumeration (I think
it is required to be an integral type, however; ie. it cannot be, for example,
'std::bitset<6>'). For enumerations the bitwise logic operations are not
automatically defined and it requires overloading them to turn the enumeration
into a bitmask. Overloading involves function calls and the result of a
function call is never a constant expression as is required in your example.

I agree that your expression should be a constant expression ie. that eg.
inline functions depending strictly only on their arguments should capable of
producing constant expression if their arguments are all constant expressions.
However, the current C++ specification has no such provision.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top