I 've got a base abstract class and 2 derived classes from base. When i get to call the function from the derived classes the program crashes!! Here's the code!
My base Class
class product{
protected:
float ipsos,aktina;
int n;
public:
product(){};
virtual float getvolume() =0;
};
My Derived class
class product1:public product{
public:
product1();
float getakt(){return aktina;};
float getips(){return ipsos;};
float getvolume();
};
product1::product1(){
//inputing aktina,ipsos,n
}
float product1::getvolume(void){
return (3.14)*aktina*aktina*ipsos;
}
I 've got another 1 derived class that has another implemantation of getvolume().. Here's my main:
int main(){
int i;float v;
product1 *p1;
product2 *p2;
if((p1=(product1*)malloc(2*sizeof(product1)))==NULL){
cout <<"Not enough memory for 2"<< "objects" << endl;
exit(1);
}
for(i=0;i<2;i++){
product1 temp;
p1[i]=temp;
}
cout<<p1[0].getakt()<<" "<<p1[0].getips();
v=p1[0].getvolume();
cout<<v;
return 1;
}
Programs does fine until it goes to v=p1[0].getvolume() where it crashes and i cant understand what the problem is!