#include<bits/stdc++.h>
using namespace std;
class test{
public:
int a, b, c;
};
int main(){
test obj = {1, 2, 3};
cout << obj.a << " " << obj.b << " " << obj.c << endl;
}
In the test class, no parameterized constructor was created, then how can an object of the test class be initialized by passing in parameters in curly braces.
This did produce an error when I added a constructor (non-parameterized) to the class but why does it not produce an error when no constructor is defined?
New contributor
user26869774 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2