int main() { std::vector<boost::shared_ptr<B> > v; for(int i = 0; i < 10; ++i) v.push_back(createB()); std::cout << "The choir is gathered:" << std::endl; for(std::vector<boost::shared_ptr<B> >::iterator it = v.begin(); it != v.end(); ++it) (*it)->sing(); // equivalent to (*(*it)).sing() -- first dereference the iterator to get vector element, then dereference vector element, which is a shared_ptr }
int main(int argc, char** argv) { int i,j, leafSum=0; struct timeval start,end; /*Original function generation 3-D points (x,y,z) that belong on the first octant of the unit sphere in three-dimentional space */ generator(); box = (Box*)malloc(sizeof(Box)); if(box==NULL){ exit(3);} gettimeofday(&start, NULL); /*BEGINNING OF CALCULATIONS - INITIALIZATION OF THE ROOT */ box[0].boxid = 1; box[0].level = 0; box[0].parent = 0; box[0].center[0] = 0.5; box[0].center[1] = 0.5; box[0].center[2] = 0.5; box[0].length = 1; box[0].start=0; box[0].n=N; box[0].points = (int*)malloc(N*sizeof(int)); for(i=0;i<N;i++){ box[0].points[i]=i; } for(i=0;i<26;i++){ box[0].colleague[i]=0; } /*MAIN THREAD BEGINS THREAD EXECUTING CALCULATING OCTREES!!*/ checkBox(0); printf("\n\nTotal n measured in boxes = %d",totalPoints); /*OPTIONAL - JUST FOR VERIFICATION*/ for(i=0;i<leafCounter;i++){ leafSum+=leaf[i].n; } printf("\nTotal n measured in leaves is %d",leafSum); gettimeofday(&end, NULL); divisionTime = ((end.tv_sec * 1000000 + end.tv_usec) -(start.tv_sec * 1000000 + start.tv_usec)); /*******FIND COLLEAGUES - PTHREADS VERSION*******/ gettimeofday(&start, NULL); remove("colleagues.txt"); findLevels(); findColleagues(); gettimeofday(&end, NULL); colleaguesTime = ((end.tv_sec * 1000000 + end.tv_usec) -(start.tv_sec * 1000000 + start.tv_usec)); createB(); gettimeofday(&start, NULL); /* printf("\nSaving in files..."); boxesFile(); leavesFile(); alphaFile(); betaFile(); timeFile(); colleaguesFile(); */ gettimeofday(&end, NULL); filesTime = ((end.tv_sec * 1000000 + end.tv_usec) -(start.tv_sec * 1000000 + start.tv_usec)); printf("\n\nOctree Division time is %d",divisionTime); printf("\nColleagues finding time is %d",colleaguesTime); printf("\nSaving data in files time is %d",filesTime); printf("\nTotal calculation time is %d",divisionTime+colleaguesTime+filesTime); printf("\n\n***END OF PROGRAM***"); return (EXIT_SUCCESS); }