Error 0133

I keep getting error 0133 that says "expected a member name" for this piece of code and I dont know why

m_leftPaddle.(&m_staticBlocks[2].getBody(m_leftPaddle));
It's not correct syntax. You can't use parentheses after the member access (.) operator like that.
What is m_leftPaddle? It's not clear what you are trying to do.

If m_staticBlocks is a member of m_leftPadde, and you are trying to get the address of the result of getBody, you would do something like
&m_leftPaddle.m_staticBlocks[2].getBody(m_leftPaddle);

"." (member access) has higher precedence than "&" (address of), so it's taking the address of the thing returned by the getBody call (assuming that is valid).
Last edited on
so my code as of now debugs the pong game but the paddles don't move and whenever the
ball collides with a paddle it moves them out of position. What I want to do is stop the paddles from moving whenever it collides with the ball so I wrote out the previous code to help with that. I think if my paddle was to get the body of the staticblock it should stop the movement.

Here is my code for this. It isn't my whole code but it's where the error is occuring

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243

//physicalThing class

#include <Box2D/Box2D.h>

#define DEG2RAD 0.017453f
#define RAD2DEG 57.29577f

class PhysicalThing {
protected:
	b2Body * m_body = nullptr; 
	float mk_fDensity = 1.0f;
	float mk_fFriction = 0.4f;
	float mk_fRestitution = 0.6f; 
public:
	void setUserData(void* data) { m_body->SetUserData(data); };
	b2Body * getBody() { return m_body; } //!< Get the body
};

//StaticObject.h class

#include <Box2D/Box2D.h>
#include <SFML/Graphics.hpp>

#include "physicalThing.h"

class StaticBlock : public sf::RectangleShape, public PhysicalThing
{
public:
	StaticBlock() {}; 
	StaticBlock(b2World * world, sf::Vector2f position, sf::Vector2f size, float orientation, sf::Color colour);
};

//StaticObject.cpp class

#include "staticBlock.h"

StaticBlock::StaticBlock(b2World * world, sf::Vector2f position, sf::Vector2f size, float orientation, sf::Color colour)
{
	b2BodyDef l_bodyDef;
	b2PolygonShape l_shape;
	b2FixtureDef l_fixtureDef;

	l_bodyDef.position.Set(position.x, position.y);
	l_bodyDef.angle = orientation * DEG2RAD;

	m_body = world->CreateBody(&l_bodyDef);
	m_body->SetUserData(this);

	l_shape.SetAsBox(size.x * 0.5f, size.y * 0.5f);
	l_shape.m_radius = 0.0f;

	l_fixtureDef.density = mk_fDensity;
	l_fixtureDef.friction = mk_fFriction;
	l_fixtureDef.restitution = mk_fRestitution;
	l_fixtureDef.shape = &l_shape;

	m_body->CreateFixture(&l_fixtureDef);

	setPosition(position);
	setSize(size);
	setOrigin(size * 0.5f);
	setRotation(orientation);
	setOutlineThickness(0.f);
	setFillColor(colour);
}

//paddle.h class

#include <Box2D/Box2D.h>
#include <SFML/Graphics.hpp>

#include "physicalThing.h"

class Paddle : public sf::RectangleShape, public PhysicalThing
{
private:
	b2MotorJoint * m_motorJoint;
public:
	Paddle() {};
	Paddle(b2World * world, sf::Vector2f position, sf::Vector2f size, const float orientation, sf::Color colour);
	void update(); 
	void setJointlinearDistance(b2Vec2 dist);
	b2Vec2 getJointLinearDistance();
};

//paddle.cpp class

#include "paddle.h"

Paddle::Paddle(b2World * world, sf::Vector2f position, sf::Vector2f size, const float orientation, sf::Color colour)
{
	b2BodyDef l_bodyDef;
	b2PolygonShape l_shape;
	b2FixtureDef l_fixtureDef;

	l_bodyDef.position.Set(position.x, position.y);
	l_bodyDef.angle = orientation * DEG2RAD;
	l_bodyDef.type = b2_dynamicBody;

	m_body = world->CreateBody(&l_bodyDef);
	m_body->SetUserData(this);

	l_shape.SetAsBox(size.x * 0.5f, size.y * 0.5f);
	l_shape.m_radius = 0.0f;

	l_fixtureDef.density = mk_fDensity;
	l_fixtureDef.friction = mk_fFriction;
	l_fixtureDef.restitution = mk_fRestitution;
	l_fixtureDef.shape = &l_shape;

	m_body->CreateFixture(&l_fixtureDef);

	setPosition(position);
	setSize(size);
	setOrigin(size * 0.5f);
	setRotation(orientation);
	setOutlineThickness(0.f);
	setFillColor(colour);
}

void Paddle::update()
{
	b2Vec2 pos = m_body->GetPosition();
	setPosition(pos.x, pos.y);
	float angle = m_body->GetAngle()* RAD2DEG;
	setRotation(angle);
}

void Paddle::setJointlinearDistance(b2Vec2 dist)
{
}

b2Vec2 Paddle::getJointLinearDistance()
{
	return b2Vec2();
}

//game.h class

#include <Box2D/Box2D.h>
#include <SFML/Graphics.hpp>

#include <vector>

#include "SFMLDebugDraw.h"

#include "paddle.h"
#include "dynamicCircle.h"
#include "staticBlock.h"

class Game : public sf::Drawable {
private:
	sf::View m_view; ordinates
	sf::Vector2f m_worldSize = sf::Vector2f(8.f, 6.f);

	b2World* m_pWorld = nullptr; 
	const int mk_iVelIterations = 7; 
	const int mk_iPosIterations = 5; 
	const b2Vec2 mk_gravity = b2Vec2(0.f, 0.f); 

	bool m_debug = false;
	SFMLDebugDraw m_debugDraw; 

	DynamicCircle m_puck; //!< Pong puck
	std::vector<StaticBlock> m_staticBlocks; //!< Walls
	Paddle m_leftPaddle; //!< Moving block
	Paddle m_rightPaddle; //!< Moving block
public:
	Game();
	~Game(); 
	void update(float timestep); 
	void draw(sf::RenderTarget &target, sf::RenderStates states) const; 
	void toggleDebug(); 
};

//game.cpp class

#include "game.h"

Game::Game()
{
	m_view.setCenter(0.f, 0.f);
	m_view.setSize(m_worldSize);

	m_pWorld = new b2World(mk_gravity);

	m_debugDraw.setWorld(m_pWorld);

	m_puck = DynamicCircle(m_pWorld, sf::Vector2f(0.f, 0.f), 0.13f, 0.0f, sf::Color::Magenta);
	m_puck.setUserData(&m_puck);

	m_staticBlocks.resize(4);
	m_staticBlocks[0] = StaticBlock(m_pWorld, sf::Vector2f(0.f, -3.0f), sf::Vector2f(8.0f, 0.25f), 0.f, sf::Color::Green);
	m_staticBlocks[1] = StaticBlock(m_pWorld, sf::Vector2f(0.0f, 3.0f), sf::Vector2f(8.0f, 0.25f), 0.f, sf::Color::Green);
	m_staticBlocks[2] = StaticBlock(m_pWorld, sf::Vector2f(-4.f, 0.f), sf::Vector2f(0.25f, 6.f), 0.f, sf::Color::Green);
	m_staticBlocks[3] = StaticBlock(m_pWorld, sf::Vector2f(4.f, 0.f), sf::Vector2f(0.25f, 6.f), 0.f, sf::Color::Green);

	m_leftPaddle = Paddle(m_pWorld, sf::Vector2f(-3.5f, 0.0f), sf::Vector2f(0.1f, 0.8f), 0.0f, sf::Color::Red);
	m_leftPaddle.setUserData(&m_leftPaddle);

        m_leftPaddle.(&m_staticBlocks[2].getBody(m_leftPaddle));

	m_rightPaddle = Paddle(m_pWorld, sf::Vector2f(3.5f, 0.0f), sf::Vector2f(0.1f, 0.8f), 0.0f, sf::Color::Blue);
	m_rightPaddle.setUserData(&m_rightPaddle);
}

Game::~Game()
{
	delete m_pWorld;
	m_pWorld = nullptr;
}

void Game::update(float timestep)
{
	m_pWorld->Step(timestep, mk_iVelIterations, mk_iVelIterations);

	m_puck.update();
	m_leftPaddle.update();
	m_rightPaddle.update();

	if (m_debug) m_debugDraw.clear();
}

void Game::draw(sf::RenderTarget &target, sf::RenderStates states) const
{
	target.setView(m_view);

	for (auto block : m_staticBlocks) target.draw(block);

	target.draw(m_leftPaddle);
	target.draw(m_rightPaddle);
	target.draw(m_puck);

	if(m_debug) target.draw(m_debugDraw);
}

void Game::toggleDebug()
{
	m_debug = !m_debug;
}

}
Last edited on
If you're going to dump that much code on us, please format it so that it's readable:

http://www.cplusplus.com/articles/z13hAqkS/
Last edited on
Sorry I didn't know about that. I'll edit it now
I don't have the bandwidth to install Box2D right now, but I still am not getting it. You're saying the code you posted compiles?

Maybe I'm crazy, but still no way that line 202 compiles.
And what is going on with line 154? sf::View m_view; ordinates

If the problem is that things are not updating properly, I would look more closely at the update functions. I also don't know where any sort of object collision testing is occurring, so those are the two places I suggest taking a closer look at when you debug. e.g. make print statements or set breakpoints at "before and after" points where you expect a position to update, and make sure that the new position is what you expect.
Last edited on
This one big lines of code isnt in one file. I just made it like this cos I though it'll make it easier to understand. Each comment represents a different file. Also I didn't write a large amount of this code which is why I don't understand it too well. In fact I can tell you all the lines I've wrote on:
78, 83, 84, 130, 137 & 202. I'm just trying to add a bit of code onto it to make it work like how I stated before which was to stop the paddle from moving when it collides with the ball.





Topic archived. No new replies allowed.