c++ Object and classes . Problems with declaration of variable using user defined type

Hello everyone, i am getting a compilation error from the code below. It is when i am naming a variable with my user defined type. Can anyone hint me on how to correct the mistake.


#include<iostream>
#include<cstring>
#include<cstdlib>

using namespace std;

class person
{
private:
char ID[10];
char SNAME[100];
char FNAME[100];
float SALARY;

public:
person(char I[],char S[],char F[] ,float SAL)
{
strcpy(ID,I);
strcpy(SNAME,S);
strcpy(FNAME,F);
SALARY=SAL;
}


void enterdetails();

void displaydetails();


};



void person :: enterdetails()
{
cout<<"Enter ID here:"<<endl;
cin.getline(ID,10);

cout<<"Enter first name here:"<<endl;
cin.getline(FNAME,100);

cout<<"Enter surname here:"<<endl;
cin.getline(SNAME,100);

cout<<"Enter salary here:"<<endl;
cin>>SALARY;

cin.ignore();
}

void person :: displaydetails()
{
cout<<"First name is"<<FNAME<<endl;
cout<<"Surname is"<<SNAME<<endl;
cout<<"ID is"<<ID<<endl;
cout<<"Salary is "<<SALARY<<endl;

}

int main ()
{
person p[2];

person X("UJIji8j", "GILDARTS","JED",1234.5);

int i;

for (i=0;i<2;i++)
{
p[i].enterdetails();

}
for(i=0;i<2;i++)
{
p[i].displaydetails();
}

cout<<X.displaydetails();

cin.ignore();

system ("pause");

return EXIT_SUCCESS;
}

C:\Dev-Cpp\TRIAL.PASS.!!!.cpp In function `int main()':
66 C:\Dev-Cpp\TRIAL.PASS.!!!.cpp expected primary-expression before "p"
66 C:\Dev-Cpp\TRIAL.PASS.!!!.cpp expected `;' before "p"
74 C:\Dev-Cpp\TRIAL.PASS.!!!.cpp `p' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
83 C:\Dev-Cpp\TRIAL.PASS.!!!.cpp `X' undeclared (first use this function)
Your class has no the default constructor. So this code

person p[2];

is invalid.
Thank you very much vlad.
Hi Vlad

According you answer to my Q "default constructor", Didn't you said that
the compiler creates a default constructor by itself. so why it should not be compiled ?

Thanks
SelfUser
If at least one constructor was declared explicitly the compiler will not create itself the default constructor implicitly.
Topic archived. No new replies allowed.