Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Help wanted. C++ question.

Name: Anonymous 2009-07-13 17:49

How do I declare a global object 'within' the class's brackets?

class Box{

public:
int x, y;
//Here's the problem.
Box A;//?

bool collision(Box A, Box B){}

}A, B;

Is it even possible to declare global objects within a class? Yes/no? Depending on your answer I may:
 
a) Drop out of college and become a plumber.
b) Kill myself.
c) Finish the app I'm currently working on.

Name: Anonymous 2009-07-13 21:15

>>28
So, box A and box B:
A.collide_with(B);. Why do you duplicate A? The collision method is a member of box A, so it receives box A as an implicit parameter.

If it's not broke; don't fix it.
The point is that it's broke. What I think you're doing is making the classic is-a/has-a confusion. A and B are boxes, they don't have boxes. You don't have a box class with storage for instances of itself, and you don't pass objects to themselves since they are themselves.

A class is not a collection of code for dealing with some particular variety of bullshit; a class is a description of the form an object is going to take. Why is a box object going to have a bunch of box variables inside it? Does that have anything to do with the nature of a box: to represent a rectangle? Likewise, an object's methods are going to involve that object, and are not going to have that object passed to it. Only pass data that doesn't already exist in the object, such another object to collide with.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List