I'll try to be brief. I have several classes in my program, and now I'm having trouble making them work together. The details: I have classes Ball (Ball.cpp + Ball.h) and Wall (Wall.cpp + Wall.h). I was trying to create a new function in Ball with a parameter of type Wall, as follows:
Code:
class Ball
{
[...]
bool CB_col(Wall blck) const;
[...]
};
This is its declaration in Ball.h, line 27. It is also mentioned in Ball.cpp properly.
However, the compiler doesn't seem to accept the code:
I've searched through many places about this, but this just feels different from all others. There is absolutely no semi-comma or bracket missing in any of the 4 files.
If there isn't enough info on the problem, it can be provided when requested. Thanks in advance.
I'll try to be brief. I have several classes in my program, and now I'm having trouble making them work together. The details: I have classes Ball (Ball.cpp + Ball.h) and Wall (Wall.cpp + Wall.h). I was trying to create a new function in Ball with a parameter of type Wall, as follows:
Code:
class Ball
{
[...]
bool CB_col(Wall blck) const;
[...]
};
This is its declaration in Ball.h, line 27. It is also mentioned in Ball.cpp properly.
However, the compiler doesn't seem to accept the code:
I've searched through many places about this, but this just feels different from all others. There is absolutely no semi-comma or bracket missing in any of the 4 files.
If there isn't enough info on the problem, it can be provided when requested. Thanks in advance.
If you have two classes which work together you better pass argument of the other class by reference rather than by value. Passing by value would make a copy what means in your case that when you pass a wall object to the ball you would get a second wall as a copy in the ball function. That hardly would make sense. I assume you have two walls and one ball, so whenever you pass one of these objects you best pass them by reference.
Many thanks for the quick replies. I admit I did the header guards in a bit of a hurry, so I will check into that.
I've understood the idea of passing the parameter by reference, and I agree with that. Guess I was too used to Java.
I performed a complete replacement of the code to accept this declaration:
Bookmarks