On 3/24/07, Robert Ryan <[EMAIL PROTECTED]> wrote:
> I want to make a square, a circle and a triangle in C++
>   do I start off with just making generalizations about a Shape and then get 
> specific for each shape
>
>   #include <iostream>
> using namespace std;
> class Shape {
> double Diam = 0;
>   double Circum1 = 0;
>   double Circum2 = 0;
>   double Circum3 = 0;
>   }
>   public Square extends Shape {
>   double side = 5;
>   Circum1 = 4*side;
>   }
>
>   public  Circle extends Shape {
>   double radius = 5;
>   double circumference = 0;
>   Circum2 = PI r2;
>   }
>
>   public  Triangle extends Shape {
>   double side = 5;
>   Circum3 = l+l+l;
>   }
>
>   int main() {
> Shape s s("Circle", "Square", "Triangle",  true);
> cout << b.get_Circum1() <<endl;
> cout << b.get_Circum2( ) << endl;
> cout << b.get_Circum2( ) << endl;
> }

Yes, you make an abstract base class and then derive the specific
shape classes from that. This is the most basic principle of
object-oriented programming.

Note there is no 'extends' keyword in C++ -- you are confusing it with
Java again. The code as you have above is not even valid C++. You
declare s as a Shape and use a constructor that takes three strings,
but you have declared no such constructor. And if you are creating
derived classes, you should be creating those objects directly. And
what is b? Where have you declared get_Circum1() or get_Circum2() or
get_Circum3()?

-- Brett
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
    If I were to divulge it, it would overturn the world."
               -- Jelaleddin Rumi

Reply via email to