Re: std::vector error
"Vladimir Grigoriev" <vlad.moscow@mail.ru> ha scritto nel messaggio
news:uJwMflZfKHA.6096@TK2MSFTNGP02.phx.gbl...
So the code should look the following way
[...]
What is the matter?
It seems working OK on VC9 with SP1:
c:\tmp>type test.cpp
#include <iostream>
#include <vector>
struct Point
{
explicit Point( int i = 0, int j = 0 ): x( i ), y( j ) {}
Point( const Point &rhs ): x( rhs.x ), y( rhs.y ) {}
~Point() {}
Point & operator =( const Point &rhs )
{
x = rhs.x; y = rhs.y;
return ( *this );
}
Point & operator -=( const Point &rhs )
{
x -= rhs.x; y -= rhs.y;
return ( *this );
}
Point & operator --()
{
*this -= Point( 1, 1 );
return ( *this );
}
const Point operator --( int )
{
Point tmp = *this;
--*this;
return ( tmp );
}
const Point operator -() const
{
return ( Point( -x, -y ) );
}
int x, y;
};
inline std::ostream & operator <<( std::ostream &os, const Point &rhs )
{
os << "{" << rhs.x << ", " << rhs.y << "}";
return ( os );
}
inline bool operator ==( const Point &lhs, const Point &rhs )
{
return ( ( lhs.x == rhs.x ) && ( lhs.y == rhs.y ) );
}
inline bool operator !=( const Point &lhs, const Point &rhs )
{
return ( !( lhs == rhs ) );
}
template <typename T>
inline const T operator -( const T &lhs, const T &rhs )
{
return ( T( lhs ) -= rhs );
}
#define MAX_SIZE 10
int main(void)
{
std::vector<Point> v;
v.reserve( MAX_SIZE );
for ( int i = 0; i < MAX_SIZE; ++i )
{
v.push_back( Point( i, i ) );
}
return 0;
}
c:\tmp>cl /EHsc /nologo /W4 /MT /O2 /GL test.cpp
test.cpp
Generating code
Finished generating code
Giovanni