i'm trying to create array of object and display it but for some reason it's giving wrong out put i think i'm using the new operator wrong way but i'not sure what's wrong
#include<bits/stdc++.h>
using namespace std;
class X {
string s;
int b;
public:
void set(string s,int b ) {
this->s = s;
this->b = b;
}
void display() {
cout << this->s << ' ' << this->b << '\n';
}
};
int main()
{
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n;
cin >> n;
X* a = new X[n];
for (int j = 0; j < n; j++) {
string s; int b;
cin >> s >> b;
a[i].set(s, b);
}
for (int i = 0; i < n; i++) {
a[i].display();
}
}
}
input: 1 3 abhi 1 omkar 2 ritesh 3
output: ritesh 3 0 0