illegel indirecion

M

MiKy

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;

};
 
D

Dan

MiKy said:
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.
 
P

Pete C.

MiKy said:
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)
a[*count_circle].SetArea(p1);
}
<snip>

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

- Pete
 
M

markspace

MiKy said:
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;

};
 
J

John Harrison

markspace said:
MiKy said:
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
 
J

JKop

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
 
K

Karl Heinz Buchegger

JKop said:
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*
 
R

Ron Samuel Klatchko

Karl Heinz Buchegger said:
JKop said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top