I have two classes; primatives.h

class PS2Sprite 
{
public:

	PS2Sprite::PS2Sprite();
	
	PS2Sprite::PS2Sprite(const float x, const float y);
	
	PS2Sprite::~PS2Sprite();
	
	virtual void Render(void) const;
	virtual void RenderPerspective(void) const;
	
	void MoveTo(const float x, const float y, const float z);
	
	void Rotate(const float angle);
	void Rotate(const float angle, const uint8 x, const uint8 y);

protected:

	void Initialise(void);		// Initialise variables

	float m_x, m_y;				// position on screen
	float m_z;					// z depth (big = near)
	float m_w, m_h;				// width and height
	
	struct Point{
		float x, y;
	}m_TopLeft, m_BottomLeft, m_TopRight, m_BottomRight;
};

The rotate function in primatives.cpp

void PS2Sprite::Rotate(float angle)
{   
	Cmaths.Rotate(&m_TopLeft, angle);
	Cmaths.Rotate(&m_BottomLeft, angle);
	Cmaths.Rotate(&m_TopRight, angle);
	Cmaths.Rotate(&m_BottomRight, angle);
}

My maths.h

#define Cmaths maths::GetSingleton()

class maths : public CSingleton<maths>
{
	
public: 

	maths::maths();
	maths::~maths();

	void Rotate(struct Point *point, const float angle);
	
protected:

	float oldx, oldy;   //store coordinates
	
};

and maths.cpp

void maths::Rotate(struct Point *point, float angle)
{
	oldx= *point.x;
	oldy= *point.y;
	*point.x= oldx*Cos(angle)-oldy*Sin(angle);
	*point.y= oldx*Sin(angle)+oldy*Cos(angle);

}

when I compile I get this error:

primitives.cpp: In method `void PS2Sprite::Rotate(float)':
primitives.cpp:133: no matching function for call to `maths::Rotate (PS2Sprite::Point *, float &)'
maths.h:21: candidates are: void maths::Rotate(Point *, float)

Am I coming at this in completely the wrong way or is it something small I've over looked?

Recommended Answers

All 3 Replies

looks like there are :: Point and PS2Sprite:: Point ,
the compiler ambigious on this point.

void maths::Rotate(PS2Sprite::Point *point, float angle)
{
	oldx= *point.x;
	oldy= *point.y;
	*point.x= oldx*Cos(angle)-oldy*Sin(angle);
	*point.y= oldx*Sin(angle)+oldy*Cos(angle);

}

Struct point is defined in the protected section of the class PS2Sprite, which means it can not be used outside that class. If you want to use that structure like you are doing then move its definition outside any class.

looks like there are :: Point and PS2Sprite:: Point ,
the compiler ambigious on this point.

void maths::Rotate(PS2Sprite::Point *point, float angle)
{
	oldx= *point.x;
	oldy= *point.y;
	*point.x= oldx*Cos(angle)-oldy*Sin(angle);
	*point.y= oldx*Sin(angle)+oldy*Cos(angle);

}

I'm aware thats the problem but for that to work I'd have to #include primatives.h (the first class) which then throws up a huge amount of errors.

Struct point is defined in the protected section of the class PS2Sprite, which means it can not be used outside that class. If you want to use that structure like you are doing then move its definition outside any class.

Where would I move it? It doesn't seem right just sticking it in main.cpp.

Edit: I moved the struct into the public section of primitives.h and just sent the address of the floats in the struct and now it's telling me: assignment of read-only location. I thought public meant I could edit them?

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.