The hex hex.


R. Clayton (rclayton@clayton.cs.monmouth.edu)
(no date)


  The book showns that ios::hex is defined in header file <iomanip>. I tried
  compiling the code from the quiz and it compiled without any problem. How is
  this possible?

There are two or three things going on here, all of them confusing. First,
there are two uses of the name hex: the stream manipulator std::hex and the
constant bit value ios::hex. The quiz was using the stream manipulator
std::hex; the book (I'm guessing Figure 11.20 on page 681) is using the
constant bit value ios::hex.

Second, neither hex is defined in <iomanip>. Where they're defined varies from
compiler to compiler, but they both must be defined by including <iostream>.
The book (I'm guessing Figure 11.16 on page 676) is a bit confusing on this
point because it lists the "using std::hex" after <iomanip>, suggesting that
it's defined (possibly by other inclusions) in <iomanip> (setbase, on the other
hand, is defined in <iomanip>).

Third, why didn't hex in the quiz use the scope qualifier std::? Some
compliers are lax about enforcing the standard name space std; g++ is one of
them. The solaris CC compiler enforced the std name space, but we don't have a
copy of that anymore; without a compiler to complain about namespace
violations, I tend to forget about them.

As an aside, std is a namespace, ios is a class. The statement "using
ios::hex;" would not let you refer to just "hex" because using statements only
apply to namespaces.



This archive was generated by hypermail 2.0b3 on Mon Aug 13 2001 - 15:00:04 EDT