Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Getting Error: error: request for member ‘GetX’ in ‘ball’, which is of non-class type ‘Ball ()()’

Reply
Thread Tools

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

 
 
AJ
Guest
Posts: n/a
 
      12-02-2009
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:raw(Canvas &canvas)
{
canvas.DrawCircle(X_position, Y_position, Ball_Radius);
}
/*
double Ball:istance(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
 
Reply With Quote
 
 
 
 
Johannes Schaub (litb)
Guest
Posts: n/a
 
      12-02-2009
AJ wrote:

> 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.
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      12-02-2009
AJ wrote:
> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
AJ
Guest
Posts: n/a
 
      12-03-2009
On Dec 2, 2:53*pm, "Johannes Schaub (litb)" <(E-Mail Removed)>
wrote:
> AJwrote:
> > 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.


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
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      12-03-2009
Andy Champ wrote:
> Victor Bazarov wrote:
> <snip>
>>>
>>> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
Paul N
Guest
Posts: n/a
 
      12-04-2009
On 3 Dec, 20:41, Victor Bazarov <(E-Mail Removed)> wrote:
> 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.
 
Reply With Quote
 
Joe Greer
Guest
Posts: n/a
 
      12-04-2009
Paul N <(E-Mail Removed)> wrote in news:f5933704-5aea-483e-bc31-03b5a51b2486
@c3g2000yqd.googlegroups.com:

>
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
request for member which is of non-class type error zl2k C++ 2 09-13-2010 07:26 AM
pointer to a member of a struct which is in turn a member of an arrayof structs pete142 C Programming 5 01-23-2008 01:11 AM
What is the correct grammar to make a function call by using static member data which is a pointer to a ordinary class member function? zaeminkr@gmail.com C++ 3 07-06-2007 12:50 PM
Accessing a protected member of a member of type BaseClass???? Steven T. Hatton C++ 2 08-16-2004 03:11 PM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM



Advertisments