Getting Error: error: request for member ‘GetX’ in ‘ball’, which is of non-class type ‘Ball ()()’

A

AJ

AJ

Hey Everybody I am in a bit of jam. I am new programming so please can
help will be appreciated.
Thanks In Advance

I have two header files and i am trying to call a function from ball.h
in ballpit.h, but get this error

error: request for member ‘GetX’ in ‘ball’, which is of non-class type
‘Ball ()()’

here ball.h

#########################################################################################
#ifndef CSCI135P5_BALL_H
#define CSCI135P5_BALL_H
#include "csci135canvas.h"

class Ball
{
public:
Ball(double x, double y, double vx, double vy, double radius);
Ball();
void Step();
void Draw(Canvas &canvas);
//double Distance(Ball &ball);
double GetX();
double GetY();
double GetVX();
double GetVY();
double GetRadius();
void SetX(double new_x);
void SetY(double new_y);
void SetVX(double new_VX);
void SetVY(double new_VY);
void SetRadius(double new_Radius);
private:
double X_position;
double Y_position;
double X_velocity;
double Y_velocity;
double Ball_Radius;

};
#endif
##################################################################################
here is ball.cpp

##################################################################################
#include "csci135p5ball.h"
#include "csci135canvas.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

Ball::Ball(double x, double y, double vx, double vy, double radius)
{
X_position = x;
Y_position = y;
X_velocity = vx;
Y_velocity = vy;
Ball_Radius = radius;
}
Ball::Ball()
{
srand ( time(NULL) );

double x_rand = rand() % 500;
double y_rand = rand() % 500;
double vx_rand = rand() % 5 + -5;
double vy_rand = rand() % 5 + -5;
double radius_rand = rand() % 12 + 2;

Ball(x_rand, y_rand, vx_rand, vy_rand, radius_rand);
}
void Ball::Step()
{
if (X_position == 0)
X_velocity = -(X_velocity);
else if (X_position == 500)
X_velocity = -(X_velocity);
else if (Y_position == 0)
Y_velocity = -(Y_velocity);
else if (Y_position == 500)
Y_velocity = -(Y_velocity);

X_position = X_position + X_velocity;
Y_position = Y_position + Y_velocity;

}
void Ball::Draw(Canvas &canvas)
{
canvas.DrawCircle(X_position, Y_position, Ball_Radius);
}
/*
double Ball::Distance(Ball &ball);
{

}
*/
double Ball::GetX()
{
return X_position;
}
double Ball::GetY()
{
return Y_position;
}
double Ball::GetVX()
{
return X_velocity;
}
double Ball::GetVY()
{
return Y_velocity;
}
double Ball::GetRadius()
{
return Ball_Radius;
}
void Ball::SetX(double new_x)
{
X_position = new_x;
}
void Ball::SetY(double new_y)
{
Y_position = new_y;
}
void Ball::SetVX(double new_VX)
{
X_velocity = new_VX;
}
void Ball::SetVY(double new_VY)
{
Y_velocity = new_VY;
}
void Ball::SetRadius(double new_Radius)
{
Ball_Radius = new_Radius;
}

##################################################################################

here is ballpit.h

##################################################################################
#ifndef CSCI135P5_BALLPIT_H
#define CSCI135P5_BALLPIT_H
#include "csci135canvas.h"
#include <vector>
using std::vector;

class BallPit
{
public:
BallPit(int ball_number);
void step();
void draw(Canvas &canvas);

private:
int ballpit;
double x_spot;
double y_spot;
double xv_spot;
double yv_spot;
double radius_spot;

vector<double> initial_x;
vector<double> initial_y;
vector<double> initial_xv;
vector<double> initial_yv;
vector<double> initial_radius;

};
#endif
###################################################################################

here is ballpit.cpp

####################################################################################
#include "csci135p5ballpit.h"
#include "csci135p5ball.h"
#include "csci135canvas.h"
#include <vector>
using std::vector;

BallPit::BallPit(unsigned int ball_number)
{
ballpit = ball_number;

for(unsigned int i = 0; i < ball_number; i++)
{
Ball ball();

x_spot = ball.GetX();
y_spot = ball.GetY();
xv_spot = ball.GetXV();
yv_spot = ball.GetYV();
radius_spot = ball.GetRadius();

initial_x.push_back(x_spot);
initial_y.push_back(y_spot);
initial_xv.push_back(xv_spot);
initial_yv.push_back(yv_spot);
initial_radius.push_back(radius_spot);

ball.Draw(Canvas &Bcanvas);
}

}
void BallPit::step()
{
for(unsigned int x = 0; x < ballpit; x++)
{
ball.SetX(initial_x[x]);
ball.SetY(initial_y[x]);
ball.SetVX(initial_xv[x]);
ball.SetVY(initial_xy[x]);
ball.SetRadius(initial_radius[x]);

ball.Step();

x_spot = ball.GetX();
y_spot = ball.GetY();
xv_spot = ball.GetVX);
yv_spot = ball.GetVY);
radius_spot = ball.GetRadius();

initial_x[x] = x_spot;
initial_y[x] = y_spot;
initial_xv[x] = xv_spot;
initial_yv[x] = yv_spot;
initial_radius[x] = radius_spot;
}

}
double BallPit::draw(Canvas &canvas)
{
for(unsigned int y = 0; y < ballpit; y++)
{
ball.SetX(initial_x[y]);
ball.SetY(initial_y[y]);
ball.SetVX(initial_xv[y]);
ball.SetVY(initial_xy[y]);
ball.SetRadius(initial_radius[y]);

ball.Draw(Canvas &canvas);

}
}
##################################################################################

Thank you in advance for any help.

AJ
 
J

Johannes Schaub (litb)

AJ said:
Ball ball();

That's not an object declaration, but a function declaration. Get rid of the
"()". If you don't, "ball" is associated with a type "Ball()", which is a
function type (having no parameters, returning Ball). GCC printing "Ball ()
()" is a GCC bug. Such a type does not exist, it would be invalid.
 
V

Victor Bazarov

AJ said:
AJ

Hey Everybody I am in a bit of jam. I am new programming so please can
help will be appreciated.
Thanks In Advance

I have two header files and i am trying to call a function from ball.h
in ballpit.h, but get this error

error: request for member ‘GetX’ in ‘ball’, which is of non-class type
‘Ball ()()’

I bet you think you defined an object 'ball' by doing

Ball ball();

, didn't you? And then you're trying to call a member 'GetX' on it, like so

ball.GetX();

aren't you? Well, read the
here ball.h
[..irrelevant..]

here is ball.cpp
[..irrelevant..]

here is ballpit.h

[..irrelevant..]

here is ballpit.cpp

####################################################################################
#include "csci135p5ballpit.h"
#include "csci135p5ball.h"
#include "csci135canvas.h"
#include <vector>
using std::vector;

BallPit::BallPit(unsigned int ball_number)
{
ballpit = ball_number;

for(unsigned int i = 0; i < ball_number; i++)
{
Ball ball();

Aha!

Read the FAQ. Hint: section 10.
x_spot = ball.GetX();
y_spot = ball.GetY();
xv_spot = ball.GetXV();
yv_spot = ball.GetYV();
radius_spot = ball.GetRadius();

initial_x.push_back(x_spot);
initial_y.push_back(y_spot);
initial_xv.push_back(xv_spot);
initial_yv.push_back(yv_spot);
initial_radius.push_back(radius_spot);

ball.Draw(Canvas &Bcanvas);
}

}
[..irrelevant..]


##################################################################################

Thank you in advance for any help.

AJ

V
 
A

AJ

AJwrote:

That's not an object declaration, but a function declaration. Get rid of the
"()". If you don't, "ball" is associated with a type "Ball()", which is a
function type (having no parameters, returning Ball). GCC printing "Ball ()
()" is a GCC bug. Such a type does not exist, it would be invalid.

Thank you very much for the help it helped me out alot. I remember
this for later programs
that I have to write. thanks again
 
V

Victor Bazarov

Andy said:
Victor Bazarov wrote:
here ball.h
[..irrelevant..]

here is ball.cpp
[..irrelevant..]

here is ballpit.h

[..irrelevant..]

Victor, half the time you (and I too occasionally!) tell people off for
not posting proper code. This time the guy gave all the information -
and more. You could be gentle with the snipping - he wasn't to know
which bits were needed!

I guess it's up to the reader what "irrelevant" means, isn't it? IMO,
the contents of those classes didn't play any role in the error, nor do
they mean anything in my reply (which you removed here as well). That's
why I removed them from my post. Do you think they mattered? You seem
to think that the fact that we often remove parts of the original
message when we reply should somehow affect the original poster's
understanding on how they should word their questions. I don't think so
(unless I actually say so). And I'm not going to clutter my reply with
irrelevant code, wherever it comes from.

Or are you telling me I ought to use a different word between the double
dots in my replacement text? Like the neutral "snip"? I felt like
using "irrelevant" because that's how I saw that code *in the context of
my reply*.

V
 
P

Paul N

I guess it's up to the reader what "irrelevant" means, isn't it?  IMO,
the contents of those classes didn't play any role in the error, nor do
they mean anything in my reply (which you removed here as well).  That's
why I removed them from my post.  Do you think they mattered?  You seem
to think that the fact that we often remove parts of the original
message when we reply should somehow affect the original poster's
understanding on how they should word their questions.  I don't think so
(unless I actually say so).  And I'm not going to clutter my reply with
irrelevant code, wherever it comes from.

Or are you telling me I ought to use a different word between the double
dots in my replacement text?  Like the neutral "snip"?  I felt like
using "irrelevant" because that's how I saw that code *in the context of
my reply*.

For what it's worth, I think it would be nicer to use a neutral word
like "snip". The word "irrelevant", as least as I read it, seemed as
if you were telling the OP off for including code that he should have
known to be unnecessary, which would not really be a fair criticism.

It sounds as though you didn't mean such criticism. But the newsgroups
are text-only and span a range of cultures, so how people read it is
often not what the writer intended. I think it's worth Andy pointing
out to you how this one came across.

Regards.
Paul.
 
J

Joe Greer

For what it's worth, I think it would be nicer to use a neutral word
like "snip". The word "irrelevant", as least as I read it, seemed as
if you were telling the OP off for including code that he should have
known to be unnecessary, which would not really be a fair criticism.

It sounds as though you didn't mean such criticism. But the newsgroups
are text-only and span a range of cultures, so how people read it is
often not what the writer intended. I think it's worth Andy pointing
out to you how this one came across.

Regards.
Paul.

While I can sympathize with what you say, I think that helps if people keep
in mind that the internet is full of folks who either aren't native English
speakers or who don't have the same connotations associated with words that
we do. For example, you and I might feel that the word irrelevent has
negative meanings, but stripped of all the emotions it really just means
something isn't relevent to the problem. In other words, it helps if you
have a pretty thick skin and assume that the author isn't putting you down
unless he is demeaning in several different ways. :)

joe
 

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,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top