illegel indirecion

Discussion in 'C++' started by MiKy, Jun 15, 2004.

  1. MiKy

    MiKy Guest

    I am getting this error:
    Illegal indirection at line : a[*count_circle].SetArea(p1);
    Is it possible to set an object in an array like I am trying to do ?

    void CreateCircle(Circle* a, int count_circle)
    {
    float x,y,c, z;

    cout<<" Enter the Center Point of the circle, X-Axis: " ;
    cin>> x ;

    cout<<endl;
    cout<<" Enter the Center Point of the circle, Y-Axis: " ;
    cin>> y ;
    cout<<" Enter the Color of that point: " ;
    cin>> c ;

    cout<<" Enter the radius of the circle: " ;
    cin>> z;
    cout<<endl;

    Circle p1( (x,y,c),z);
    a[*count_circle].SetArea(p1);
    }


    my class circle:

    class Circle: public Shape
    {
    public:
    Circle(){};
    Circle(Point p, float r) : Shape(p) {radius = r;
    cout<<"radius :" << radius; }

    void SetArea(Circle) {area= PI * ( pow(radius,2) ); }
    float GetArea(){ return area; }

    private:
    float radius;
    float area;

    };
     
    MiKy, Jun 15, 2004
    #1
    1. Advertising

  2. MiKy

    Dan Guest

    "MiKy" <> wrote in message
    news:pMGzc.29$...
    > I am getting this error:
    > Illegal indirection at line : a[*count_circle].SetArea(p1);
    > Is it possible to set an object in an array like I am trying to do ?
    >
    > void CreateCircle(Circle* a, int count_circle)
    > {
    > float x,y,c, z;
    >
    > cout<<" Enter the Center Point of the circle, X-Axis: " ;
    > cin>> x ;
    >
    > cout<<endl;
    > cout<<" Enter the Center Point of the circle, Y-Axis: " ;
    > cin>> y ;
    > cout<<" Enter the Color of that point: " ;
    > cin>> c ;
    >
    > cout<<" Enter the radius of the circle: " ;
    > cin>> z;
    > cout<<endl;
    >
    > Circle p1( (x,y,c),z);
    > a[*count_circle].SetArea(p1);
    > }
    >
    >
    > my class circle:
    >
    > class Circle: public Shape
    > {
    > public:
    > Circle(){};
    > Circle(Point p, float r) : Shape(p) {radius = r;
    > cout<<"radius :" << radius; }
    >
    > void SetArea(Circle) {area= PI * ( pow(radius,2) ); }
    > float GetArea(){ return area; }
    >
    > private:
    > float radius;
    > float area;



    Sorry my brother played around with my account. Its me Dan asking this
    question.

    .... a better program from the past couple of days ago.
     
    Dan, Jun 15, 2004
    #2
    1. Advertising

  3. MiKy

    Pete C. Guest

    MiKy wrote:
    > I am getting this error:
    > Illegal indirection at line : a[*count_circle].SetArea(p1);
    > Is it possible to set an object in an array like I am trying to do ?
    >
    > void CreateCircle(Circle* a, int count_circle)

    <snip>
    > a[*count_circle].SetArea(p1);
    > }

    <snip>

    count_circle is not a pointer, so you can't dereference it.

    - Pete
     
    Pete C., Jun 15, 2004
    #3
  4. MiKy

    markspace Guest

    MiKy wrote:

    > I am getting this error:
    > Illegal indirection at line : a[*count_circle].SetArea(p1);
    > Is it possible to set an object in an array like I am trying to do ?
    >
    > void CreateCircle(Circle* a, int count_circle)


    How is a an array? CreateCircle(Circle a[], ... )

    > {
    > float x,y,c, z;
    >
    > cout<<" Enter the Center Point of the circle, X-Axis: " ;
    > cin>> x ;
    >
    > cout<<endl;
    > cout<<" Enter the Center Point of the circle, Y-Axis: " ;
    > cin>> y ;
    > cout<<" Enter the Color of that point: " ;
    > cin>> c ;
    >
    > cout<<" Enter the radius of the circle: " ;
    > cin>> z;
    > cout<<endl;
    >
    > Circle p1( (x,y,c),z);
    > a[*count_circle].SetArea(p1);
    > }
    >
    >
    > my class circle:
    >
    > class Circle: public Shape
    > {
    > public:
    > Circle(){};
    > Circle(Point p, float r) : Shape(p) {radius = r;
    > cout<<"radius :" << radius; }
    >
    > void SetArea(Circle) {area= PI * ( pow(radius,2) ); }
    > float GetArea(){ return area; }
    >
    > private:
    > float radius;
    > float area;
    >
    > };
    >
    >
     
    markspace, Jun 15, 2004
    #4
  5. "markspace" <> wrote in message
    news:...
    > MiKy wrote:
    >
    > > I am getting this error:
    > > Illegal indirection at line : a[*count_circle].SetArea(p1);
    > > Is it possible to set an object in an array like I am trying to do ?
    > >
    > > void CreateCircle(Circle* a, int count_circle)

    >
    > How is a an array? CreateCircle(Circle a[], ... )
    >


    a is not an array in your code either. In a function parameter 'Circle a[]'
    is exactly the same as 'Circle *a'. Arrays cannot be parameters in C or C++.

    john
     
    John Harrison, Jun 15, 2004
    #5
  6. MiKy

    JKop Guest

    MiKy posted:

    > I am getting this error:
    > Illegal indirection at line : a[*count_circle].SetArea(p1);
    > Is it possible to set an object in an array like I am trying to do ?
    >
    > void CreateCircle(Circle* a, int count_circle)
    > {
    > float x,y,c, z;
    >
    > cout<<" Enter the Center Point of the circle, X-Axis: " ;
    > cin>> x ;
    >
    > cout<<endl;
    > cout<<" Enter the Center Point of the circle, Y-Axis: " ;
    > cin>> y ;
    > cout<<" Enter the Color of that point: " ;
    > cin>> c ;
    >
    > cout<<" Enter the radius of the circle: " ;
    > cin>> z;
    > cout<<endl;
    >
    > Circle p1( (x,y,c),z);
    > a[*count_circle].SetArea(p1);
    > }


    I can only presume that a points to the start of an array of Circle*. If
    so, replace:

    a[*count_circle].SetArea(p1);

    with

    a[count_circle]->SetArea(p1);

    or even:

    *(a[count_circle]).SetArea(p1);



    If a points to an array of Circle,


    a[count_circle].SetArea(p1);



    -JKop






    -JKop
     
    JKop, Jun 16, 2004
    #6
  7. JKop wrote:
    >
    > MiKy posted:
    >
    > > I am getting this error:
    > > Illegal indirection at line : a[*count_circle].SetArea(p1);
    > > Is it possible to set an object in an array like I am trying to do ?
    > >
    > > void CreateCircle(Circle* a, int count_circle)
    > > {
    > > float x,y,c, z;
    > >
    > > cout<<" Enter the Center Point of the circle, X-Axis: " ;
    > > cin>> x ;
    > >
    > > cout<<endl;
    > > cout<<" Enter the Center Point of the circle, Y-Axis: " ;
    > > cin>> y ;
    > > cout<<" Enter the Color of that point: " ;
    > > cin>> c ;
    > >
    > > cout<<" Enter the radius of the circle: " ;
    > > cin>> z;
    > > cout<<endl;
    > >
    > > Circle p1( (x,y,c),z);
    > > a[*count_circle].SetArea(p1);
    > > }

    >
    > I can only presume that a points to the start of an array of Circle*.


    .... then the first argument to this function would be of type Circle**.
    Since it is not you can deduce that a does not point to the start of an array
    of Circle*


    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Jun 16, 2004
    #7
  8. Karl Heinz Buchegger <> wrote in message news:<>...
    > JKop wrote:
    > >
    > > MiKy posted:
    > >
    > > > I am getting this error:
    > > > Illegal indirection at line : a[*count_circle].SetArea(p1);
    > > > Is it possible to set an object in an array like I am trying to do ?
    > > >
    > > > void CreateCircle(Circle* a, int count_circle)
    > > > {

    > >
    > > I can only presume that a points to the start of an array of Circle*.

    >
    > ... then the first argument to this function would be of type Circle**.
    > Since it is not you can deduce that a does not point to the start of an array
    > of Circle*


    A Circle* can most definitely point to an array of Circles. A Circle**
    will actually point to an array of pointers to circles. Since you have
    an array of pointers, you can then actually have any object derived from
    Circle to enable you to get polymorphic behaviour.

    But if all you have are actual circles, an array of actual instances of
    Circles would be represented by Circle*.

    samuel
     
    Ron Samuel Klatchko, Jun 16, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page