CS253: Software Development with C++

Fall 2019

IQ 10

CS253 IQ 10

Show Main.IQ10 as a slide show.

ios state flags

When an fstream open (explicitly, or via ctor) doesn’t work, which bit is set?

  1. ios::failbit
  2. ios::eofbit
  3. ios::badbit
  4. ios::openbit
  5. None of the above

failbit is set you ask for something, and don’t get it. You tried to open a file, and it failed. Therefore, failbit.

ios state flags

When an input conversion doesn’t work, which bit is set?

  1. ios::failbit
  2. ios::eofbit
  3. ios::badbit
  4. ios::convbit
  5. None of the above

failbit is set you ask for something, and don’t get it. You tried to read something, and couldn’t. Therefore, failbit.

ios state flags

When you read the fifth byte of a five-byte file, which bit is set?

  1. ios::failbit
  2. ios::eofbit
  3. ios::badbit
  4. ios::lastbit
  5. None of the above

This is not an error. You read the last byte. Sure, the next read will fail, but that’s not your problem.

Rule of Three

Which three are mentioned in the Rule of Three?

  1. default ctor, copy ctor, assignment, dtor
  2. copy ctor, assignment, dtor
  3. default ctor, assignment, dtor
  4. default ctor, copy ctor, dtor
  5. default ctor, copy ctor, assignment

Please tell me you didn’t pick an answer that mentioned four things. Big Three is copy ctor, assignment, dtor.

methods

How do I get rid of the implicitly-provided assignment operator?

  1. Foo &operator=(const Foo &) = 0;
  2. Foo &operator=(const Foo &) = delete;
  3. Foo &operator=(const Foo &) const;
  4. delete Foo &operator=(const Foo &);
  5. Simply don’t write one.

Not writing it won’t work—it’s implicitly provided. Remove it with = delete.