This program is frustrating me. I cannot for the life of me figure out what is causing this error message. It's the sort of thing where I fix one issue only to cause 10 more.

The compiler is giving me like 8 identical pairs of errors, one for each Ball.itsPosition.getX/Y call.

The first is "left of '.GetX' must have class/struct/union"
The second is "itsPosition' : is not a member of 'std::vector<_Ty>"

//point.cpp//
#include "Point.h"
#include "Ball.h" //cyclical dependency accounted for
#include <vector>
#include <math.h>

Point::Point (int x, int y) //deault x and y set to 0
{
	itsX = x;
	itsY = y;
}

Point::~Point(void)
{
}

//use the pythagorean theorum to determine the distance between two points.
//used to determine whether or not two Balls have collided
inline int Point::Distance (std::vector < Ball > Ball_1, std::vector < Ball > Ball_2)
{
    return sqrt( ((Ball_2.itsPosition.GetX() - Ball_1.itsPosition.GetX()) * (Ball_2.itsPosition.GetX() - Ball_1.itsPosition.GetX())) + ((Ball_2.itsPosition.GetY() - Ball_1.itsPosition.GetY()) * (Ball_2.itsPosition.GetY() - Ball_1.itsPosition.GetY())) );
}

inline int Point::Distance(std::vector < Ball > Ball_1, class PlayerBall Ball_2) //the class is PlayerBall
{
	return sqrt( ((Ball_2.itsPosition.GetX() - Ball_1.itsPosition.GetX()) * (Ball_2.itsPosition.GetX() - Ball_1.itsPosition.GetX())) + ((Ball_2.itsPosition.GetY() - Ball_1.itsPosition.GetY()) * (Ball_2.itsPosition.GetY() - Ball_1.itsPosition.GetY())) );
}

here is my ball.h class

#pragma once
#include "Point.h" //because Ball is a composition
#include "Velocity.h"
#include <vector>

class Ball {
      public:
		  Ball(int, int);
		  ~Ball();

		  void WallCollision ();             
          void ApplyForce ();
		  //accessor methods

		  void SetExistence (bool truth) { itsExistence = truth; }
		  int GetExistence () const { return itsExistence; }

      private:
		  Point itsPosition;
		  Velocity itsVelocity;
		  bool itsExistence;
};

Does anyone know what syntax error I'm making here.

Recommended Answers

All 7 Replies

Ball_1 is a vector object. A vector object do not have a .itsposition member.
Try Ball_1.itsPosition
or better: pass Ball Ball_1 as the argument of function Distance rather than std::vector < Ball > Ball_1

thank you very much... Now I have another problem.
I've commented the errors on their appropriate lines below

//ball.h//
#pragma once
#include "Point.h"
#include "Velocity.h"
#include <vector>

class Ball {
      public:
		  Ball(int, int);
		  ~Ball();

		  void WallCollision ();             
          void ApplyForce ();
		  //accessor methods

		  void SetExistence (bool truth) { itsExistence = truth; }
		  int GetExistence () const { return itsExistence; }

      private:
		  Point itsPosition;  //missing ';' before identifier 'itsPosition'
//Immediately after it reads missing type specifier - int assumed.
		  Velocity itsVelocity;
		  bool itsExistence;
};

It apparently believes that I never defined a class Point.
I surely did... I'll post the Point.h file below. I also included the Point.h file. I'm not sure what's going wrong here.

//point.h//
#pragma once
#include <vector>
#include "PlayerBall.h"

class Ball;  //placed in the Point.h file here to account for cyclical dependency
//No definition included//

//Point.h//
class Point {
      public:
             Point (int x =0, int y = 0);
             ~Point ();
             
             //accessor methods
			 inline int Distance (Ball Ball_1, Ball Ball_2);

			 //player Ball and other Ball can collide and two other Balls can collide
			 inline int Distance (Ball Ball_1, PlayerBall Ball_2);

             void SetX ( int x ) { itsX = x; }
             void SetY ( int y ) { itsY = y; }
             int GetX() const { return itsX; }
             int GetY() const { return itsY; }
             
      private:
              int itsX;
              int itsY;
};

It's got to be something wrong with the linking.
any ideas?

thank you for the help in advance

What do you have in PlayerBall.h?

What do you have in PlayerBall.h?

It's basically empty... it actually is empty.

#pragma once
#include "Ball.h"

class PlayerBall : public Ball
{
public:
	PlayerBall(int, int);
	~PlayerBall();

             //get input from the mouse using SDL functions
             
      private:
              //add any needed variables for SDL functions to execute.
};

I think I have found out what exactly the problem is.

Consider this file

Point.h which uses PlayerBall.h which inturn uses Ball.h

So we will have something like this to the compiler.(I mean the compiler would see the files like this, ie read the uppermost file first then so on.)


Ball.h
PlayerBall.h
Point.h

Hence The Compiler Doesnt know that a type Point exists while it is in Ball.h

Fast FIX
I would try to Just Write down a proto-type declared in Ball.h And see whether the code compiles.

The complier is complaining that Point Ball::itsPosition is private in point.cpp in the both int Point::Distance ( ) functions.

Here is a copy of point.cpp

#include "Point.h"
#include "Ball.h" //cyclical dependency accounted for
#include "PlayerBall.h"
#include <vector>
#include <math.h>

Point::Point (int x, int y) //deault x and y set to 0
{
	itsX = x;
	itsY = y;
}

Point::~Point(void)
{
}

//use the pythagorean theorum to determine the distance between two points.
//used to determine whether or not two Balls have collided
inline int Point::Distance (Ball Ball_1, Ball Ball_2)
{
    return sqrt( ((Ball_2.itsPosition.GetX() - Ball_1.itsPosition.GetX()) * (Ball_2.itsPosition.GetX() - Ball_1.itsPosition.GetX())) + ((Ball_2.itsPosition.GetY() - Ball_1.itsPosition.GetY()) * (Ball_2.itsPosition.GetY() - Ball_1.itsPosition.GetY())) );
}

inline int Point::Distance(Ball Ball_1, PlayerBall Ball_2) //the class is PlayerBall
{
	return sqrt( ((Ball_2.itsPosition.GetX() - Ball_1.itsPosition.GetX()) * (Ball_2.itsPosition.GetX() - Ball_1.itsPosition.GetX())) + ((Ball_2.itsPosition.GetY() - Ball_1.itsPosition.GetY()) * (Ball_2.itsPosition.GetY() - Ball_1.itsPosition.GetY())) );
}

thanks for the help again

Basically your implementation of finding distances between 2 Ball classes in a Point class is quite a over-head.

I think you should provide a function to find distances between 2 points instead of balls.

After that you can use that function to find the distance between ball classes. as well as PlayerBall class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.