google 'initializer list in C++'
the data can be initialized using initializer list in constructor.
Robert Ryan wrote:
> by a constructor, do you mean:
> #include <iostream>
> using namespace std;
> class Shape {
> double radius=0;
> double side=0;
> double length=0;
> double Circum1 = 0;
> double Circum2 = 0;
> double Circum3 = 0;
>
> public:
> Shape(double r, radius s, double l):radius(r) , side(s), length(l){ }
> double get_radius() {return radius;}
> double get_side() {return side;}
> double get_length() {return author;}
> ;
>
> Square : public Shape {
> double side = 5;
> Circum1 = 4*side;
> return Circum1;
> }
> Circle : public Circle {
> double radius = 5;
> double circumference = 0;
> Circum2 = PI* r2;
> return Circum2;
> }
>
> Triangle: public Triangle {
> double side = 5;
> Circum3 = l+l+l;
> return Circum3;
> }
> int main() {
> Shape s("Circle", "Square", "Triangle");
> cout << get_Circum1( ) <<endl;
> cout << get_Circum2( ) << endl;
> cout << get_Circum3( ) << endl;
> }
> }
>
> and Yes, I am very slow at picking up this C++........I will run this
> tomorrow after I read some more stuff
>
>
> Tamas Marki <[EMAIL PROTECTED]> wrote:
> 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
>>
>
> And your question is...?
>
>
>> #include <iostream>
>> using namespace std;
>> class Shape {
>> double Diam = 0;
>>
>
> You cannot assign a default value to a member like this. You have to
> use a constructor.
>
>
>> double Circum1 = 0;
>> double Circum2 = 0;
>> double Circum3 = 0;
>> }
>>
>
> Class definitions need to end with a semicolon.
>
>
>> public Square extends Shape {
>>
>
> This is not the C++ syntax of inheritance (maybe it's Java?).
> Proper way:
>
> Square : public Shape {
>
> Those are just some syntax errors, I'm not going to make comments on
> the correctness of your logic.
> Please at least post syntactically correct snippets of code, along
> with your questions.
> The least you could do is to let your program through a compiler to
> spot the obvious errors.
>
>