i just made a person class and defined 2 overloaded constructors as u see
then made an array of 2 objects but some error pops up !
why i get these 2 errors guys please ??
and what’s the [-fpermissive] error ??
#include <iostream>
using namespace std;
class person
{
int x;
public:
person() {
x=0;
}
person(int y){ //error
x=y;
}
};
int main()
{
int n;
cin>>n;
person* Arr= new person[2];
Arr[0]=new person(n); //error
return 0;
}
You didn’t post the errors, but I assume they were,
You have two options. One, make an array of person pointers that point to person objects you create with the “new” keyword and that reside on the heap.
You could also make an array of persons and then set them equal to another person, which doesn’t require the new keyword. These would reside on the stack.