H
hellwolf
Hi,everyone.Because of my English level,I will try to use code to explain
where I confused.
//list of code:
#include <iostream>
#include <algorithm>
#include <vector>
class A{
static int si;
int i;
public:
A():i(si++){}
void show()const{std::cout << i << std::endl;}
};
int A::si(0);
class funA{
public:
void operator ()(A& a){a.show();}
};
int main(){
std::vector<A> veca(10);
std::for_each(veca.begin(),veca.end(),funA());
//system("pause");
}
result:
0
0
0
0
0
0
0
0
0
0
So ,isn't the vector call the constructor function for each member??
where I confused.
//list of code:
#include <iostream>
#include <algorithm>
#include <vector>
class A{
static int si;
int i;
public:
A():i(si++){}
void show()const{std::cout << i << std::endl;}
};
int A::si(0);
class funA{
public:
void operator ()(A& a){a.show();}
};
int main(){
std::vector<A> veca(10);
std::for_each(veca.begin(),veca.end(),funA());
//system("pause");
}
result:
0
0
0
0
0
0
0
0
0
0
So ,isn't the vector call the constructor function for each member??