Threads copy their arguments, so your threads never change the C
. If you want a reference explicitly, you have to wrap it with std::ref (or std::cref for constant references):
void f1(Case1& passedObj, int age, int index)
{
passedObj.addToAges(age, index);
}
void main(){
Case1 C;
thread t1(f1, std::ref(C), 13, 0);
t1.join();
thread t2(f1, std::ref(C), 14, 2);
t2.join();
cout << *C.pplAges[0] << endl;
cout << *C.pplAges[2] << endl;
}