how to find Expression must have class type

#include<iostream>
#include<math.h>
#include<string>
using namespace std;

class houseinfo{

private:
string name;
string address;
int bed;
int price;
public:
void getdata(char string[],char string1[],int a,int b)
{
name=string;
address=string1;
bed=a;
price=b;

}
void display()
{


cout<<name<<" "<<address<<" "<<bed<<" "<<price<<endl;

}
void sort(){

houseinfo haw[2];

/*for(int i=0;i<2;i++){

}
for(int i=0;i<2;i++){
for(int j=0;j<2-1;j++){
if(haw[j].price<haw[j+1].price){
hold = haw[ j ].price;
haw[ j ].price = haw[ j + 1 ].price;
haw[ j + 1 ].price = hold;

}

}

}*/
for(int i=0;i<2;i++){
haw[i].display();
}
}
void display2()
{


cout<<" "<<price<<endl;

}

};
void main()
{
int temp=0;
int temp1=0;
houseinfo detail[2];
char string[15],string1[30];
int a,b;
houseinfo *ha;

for(int i=0;i<2;i++)
{

cout<<"Enter Owner Name:-"<<endl;
cin>>string;
cout<<"Enter Address please?"<<endl;
cin>>string1;
cout<<"Enter No Of BedRooms"<<endl;
cin>>a;
cout<<"Enter Price "<<endl;
cin>>b;
cout<<endl;
detail[i].getdata(string,string1,a,b);


//detail.display();
}
cout<<"***********INFORMATION***********"<<endl;
for(int j=0;j<2;j++)
{
detail[j].display();
}
ha=detail;

ha.sort();//Expression must have class type
for(int j=0;j<2;j++)
{

ha[j].display2();
}
}
closed account (o3hC5Di1)
Hi there,

Please put your code between [code][/code]-tags. Also, if you have a problem, please state it clearly instead of just giving us a bunch of code.

As for your problem:

1
2
3
4
houseinfo *ha;
//...
ha.sort(); //ha is a pointer, so you need to use the arrow operator:
ha->sort();


All the best,
NwN
Please use code tags when posting code, to make it readable.

You've declared ha as a pointer, not an object with a class type:

houseinfo *ha;
Topic archived. No new replies allowed.