- Vectors of pointers to other vector's elements
- void Function(std::vector<type>* aa)
- void Function(std::vector<type>* aa)
- {
- std::vector<type*> temp; //to this vector I filter out data and by changning
- //values of this vector I want to autmatically change values of aa vector
- }
- void Announce_Event(std::vector<Event>& foo)
- {
- std::vector<Event> current;
- tm current_time = {0,0,0,0,0,0,0,0,0};
- time_t thetime;
- thetime = time(NULL);
- localtime_s(¤t_time, &thetime);
- for (unsigned i = 0; i < foo.size(); ++i) {
- if (foo[i].day == current_time.tm_mday &&
- foo[i].month == current_time.tm_mon &&
- foo[i].year == current_time.tm_year+1900)
- {
- current.push_back(foo[i]);
- }
- }
- std::cout << current.size() << std::endl;
- current[0].title = "Changed"; //<-- this is suppose to change value.
- }
- void Func(std::vector<type> & aa)
- {
- std::vector<type*> temp;
- // I wish <algorithm> had a 'transform_if'
- for(int i=0; i<aa.size(); ++i)
- {
- if( some_test(aa[i]) )
- temp.push_back(&aa[i])
- }
- // This leaves temp with pointers to some of the elements of aa.
- // Only those elements which passed some_test(). Now any modifications
- // to the dereferenced pointers in temp will modify those elements
- // of aa. However, keep in mind that if elements are added or
- // removed from aa, it may invalidate the pointers in temp.
- }
- void Function(std::vector<type>& aa)
- void Function(std::vector<type>& aa)
- {
- std::vector<type>& temp = aa;
- // if you now append something to temp, it is also appended to aa
- aa.push_back(type());
- }
- void Oglos_Wydarzenie(std::vector<Wydarzenie>& zmienna)
- {
- std::vector<Wydarzenie *> obecne;
- tm AktualnyCzas = {0,0,0,0,0,0,0,0,0};
- time_t czas;
- czas = time(NULL);
- localtime_s(&AktualnyCzas,&czas);
- for (unsigned i = 0; i < zmienna.size(); ++i) {
- if (zmienna[i].dzien == AktualnyCzas.tm_mday &&
- zmienna[i].miesiac == AktualnyCzas.tm_mon &&
- zmienna[i].rok == AktualnyCzas.tm_year+1900)
- {
- obecne.push_back(&zmienna[i]);
- }
- }
- std::cout << obecne.size() << std::endl;
- obecne[0]->tytul = "Changed"; //<-- this is suppose to change value.
- }
- void Oglos_Wydarzenie(std::vector<Wydarzenie>* zmienna)
- {
- std::vector<Wydarzenie *> obecne;
- tm AktualnyCzas = {0,0,0,0,0,0,0,0,0};
- time_t czas;
- czas = time(NULL);
- localtime_s(&AktualnyCzas,&czas);
- for (unsigned i = 0; i < zmienna->size(); ++i) {
- if ((*zmienna)[i].dzien == AktualnyCzas.tm_mday &&
- (*zmienna)[i].miesiac == AktualnyCzas.tm_mon &&
- (*zmienna)[i].rok == AktualnyCzas.tm_year+1900)
- {
- obecne.push_back(&((*zmienna)[i]));
- }
- }
- std::cout << obecne.size() << std::endl;
- obecne[0]->tytul = "Changed"; //<-- this is suppose to change value.
- }