#include <iostream>
#include <string>
using namespace std;
class shapes
{
protected:
int width;
int height;
public:
shapes()
{
width=0;
height=0;
}
~shapes()
{
}
void getWidth()
{
cout<<"What is the width"<<endl;
cin>>width;
}
void getHeight()
{
cout<<"What is the height"<<endl;
cin>>height;
}
};
class rectangle:public shapes
{
public:
void area()
{
cout<<"Your area for the rectangle is "<<(height*width)<<endl;
}
};
class triangle:public shapes
{
private:
int side;
public:
void getSide()
{
cout<<"What is the side?"<<endl;
cin>>side;
}
void area()
{
cout<<"your area for the square is"<< (width*height*side)<<endl;
}
};
void main()
{
triangle *pointer=new triangle;
pointer->getWidth();
pointer->getHeight();
pointer->getSide();
pointer->area();
delete pointer;
rectangle *pointer=new rectangle;
pointer->getHeight();
pointer->getWidth();
pointer->area();
delete pointer;
system("PAUSE");
}
I am getting an error message telling me to "see declaration of 'pointer'".
I am assuming I am not allowed to do this
delete pointer;
rectangle *pointer=new rectangle;
But I don't understand why.
I deleted pointer, aka deallocated the memory. Then I am creating a new pointer, which just happens to have the same name. Am I not allowed to do this? I thought that was the whole point of using 'pointers'.
Any helpful advise would be greatly appreciated.