J
Jason Heyes
My main program
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#include "M.h"
using namespace std;
int main()
{
vector<M> v;
typedef istream_iterator<auto_ptr<M> > InIt;
copy(InIt(cin), InIt(), back_inserter(v));
return 0;
}
will not compile under VC++ 6.0. It says
Compiling...
Main.cpp
c:\program files\microsoft visual studio\vc98\include\iterator(176) : error
C2679: binary '>>' : no operator defined which takes a right-hand operand of
type 'class std::auto_ptr<class M>' (or there is no acceptable conversion)
c:\program files\microsoft visual studio\vc98\include\iterator(176)
: while compiling class-template member function 'void __thiscall
std::istream_iterator<class std::auto_ptr<class M>,char,struct
std::char_traits<char> >::_Getval(void)'
Error executing cl.exe.
Examples.exe - 1 error(s), 0 warning(s)
but look at M.cpp
#include "M.h"
using namespace std;
istream &operator>>(istream &is, auto_ptr<M> &m)
{
char c;
is >> c;
m = auto_ptr<M>(new M);
return is;
}
and M.h
#include <memory>
#include <istream>
class M
{
public:
M() {}
M(const std::auto_ptr<M> &m) { }
friend std::istream &operator>>(std::istream &is,
std::auto_ptr<M> &m);
};
What's weird is that if I swap around these two lines in my main program
#include "M.h"
using namespace std;
so that it reads as
using namespace std;
#include "M.h"
then everything compiles fine. Please help! I have been trying to understand
this for hours...
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#include "M.h"
using namespace std;
int main()
{
vector<M> v;
typedef istream_iterator<auto_ptr<M> > InIt;
copy(InIt(cin), InIt(), back_inserter(v));
return 0;
}
will not compile under VC++ 6.0. It says
Compiling...
Main.cpp
c:\program files\microsoft visual studio\vc98\include\iterator(176) : error
C2679: binary '>>' : no operator defined which takes a right-hand operand of
type 'class std::auto_ptr<class M>' (or there is no acceptable conversion)
c:\program files\microsoft visual studio\vc98\include\iterator(176)
: while compiling class-template member function 'void __thiscall
std::istream_iterator<class std::auto_ptr<class M>,char,struct
std::char_traits<char> >::_Getval(void)'
Error executing cl.exe.
Examples.exe - 1 error(s), 0 warning(s)
but look at M.cpp
#include "M.h"
using namespace std;
istream &operator>>(istream &is, auto_ptr<M> &m)
{
char c;
is >> c;
m = auto_ptr<M>(new M);
return is;
}
and M.h
#include <memory>
#include <istream>
class M
{
public:
M() {}
M(const std::auto_ptr<M> &m) { }
friend std::istream &operator>>(std::istream &is,
std::auto_ptr<M> &m);
};
What's weird is that if I swap around these two lines in my main program
#include "M.h"
using namespace std;
so that it reads as
using namespace std;
#include "M.h"
then everything compiles fine. Please help! I have been trying to understand
this for hours...