This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Why does this not compile?


I've read a lot but I can't seem to find any references on this problem.  It
seems to be a reasonable construct.  Why have you decided to forbid this?  

#include <iostream>

class binary
{
public:
  binary( int& c ) : m_c(c) {}
private:
  int& m_c;
  friend istream& operator>>( istream& is, binary& b );
};

istream& operator>>( istream& is, binary& b )
{
  is.read( &b.m_c, sizeof(b.m_c) );
  return is;
}

int main()
{
  int b;
  cin >> binary(b);
}

bash-2.04$ g++ in.cpp
in.cpp: In function `int main ()':
in.cpp:21: could not convert `binary((&b))' to `binary &'
in.cpp:13: in passing argument 2 of `operator>> (istream &, binary &)'
bash-2.04$ g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-85)

Also, it would be very helpful if your warnings and errors were numbered.
Then, finding documentation on errors and warnings would be much easier.
Also, enabling/disabling specific warnings would be much easier.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]