Home > Back-end >  The compiler doesn't know my class
The compiler doesn't know my class

Time:03-26




simple inheritance, but perform to sp=new Rectangle (4, 6); Compiler start error
vs and cb don't know...

 # include & lt; iostream> 
# include & lt; Windows. H>
using namespace std;
The class hierarchy
{
Public:
Shape () {}
To Shape () {}
Virtual float GetArea ()
{
return -1;
}
};

The class Circle: public Shape
{
Public:
Circle (radius, float) : itsRadius (radius) {}
~ Circle () {}
Float GetArea ()
{
3.14 * * itsRadius itsRadius return (float);
}
Private:
Float itsRadius;
};

Class a Rectangle: public Shape
{
Private:
Float itsWidth;
Float itsLength;
Public:
A Rectangle (float len, float width)
{
ItsLength=len;
ItsWidth=width;
};
~ a Rectangle () {};
Virtual float GetArea ()
{
Return itsLength * itsWidth;
}
Virtual float GetLength ()
{
Return itsLength;
}
Virtual float GetWidth ()
{
Return itsWidth;
}
};

The class Square: public Rectangle
{
Public:
Square (float len) : a Rectangle (len, len) {};
~ Square () {};
};


Int main ()
{
System (" color F3 ");
Shape * sp;
Sp=new Circle (5);
Cout & lt; <"The area of The Circle is" & lt; The delete sp;

Sp=new Rectangle (4, 6);
Cout & lt; <"The area of The Rectangle is" & lt; The delete sp;

Sp=new Square (5);
Cout & lt; <"The area of The Square is" & lt; The delete sp;
return 0;
}

CodePudding user response:

Will be the name of the class class Rectangle, instead: class Rectangle_m try,
  • Related