ios::openmode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc Schellens

    ios::openmode

    When I do:

    static const ios_base::openm ode emptyMode = (
    ~(ios_base::app |
    ios_base::ate|
    ios_base::binar y|
    ios_base::in|
    ios_base::out|
    ios_base::trunc ));

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

    why?
    thanks,
    marc

  • Dietmar Kuehl

    #2
    Re: ios::openmode

    Marc Schellens <m_schellens@ho tmail.com> wrote:[color=blue]
    > the complier says:
    > io.hpp:43: field initializer is not constant
    > why?[/color]

    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.
    --
    <mailto:dietmar _kuehl@yahoo.co m> <http://www.dietmar-kuehl.de/>
    Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.co m/>

    Comment

    Working...