#include<iostream>
using namespace std;
class INCREMENT
{
public:
INCREMENT( int v = 0, int i = 1 );
void addIncrement()
{
v += increment;
}
void print() const;
int get() const
{
return v;
}
private:
int v;
const int increment;
};
INCREMENT::INCREMENT( int v, int i ) : v( v ), increment( i )
{
}
void INCREMENT::print() const
{
cout << v << endl;
}
int main()
{
INCREMENT value( 1, 2);
value.print();
for ( int j = 1; j <= 2; j++ )
{
value.addIncrement();
value.print();
}
return 0;
}
为什么结果第一行先输出1啊?