prototyping classes?
I have 2 classes CBall, and CPaddle, then I have declared an instance of each:
CBall Ball;
CPaddle Paddle;
But the problem is that CBall uses Paddle, and CPaddle uses Ball, how would I declare this? Is there some way to prototype the class, like you do for functions?
Thanks
t2sherm ô¿ô
t2sherm ô¿ô
//I am still getting problems. If i do this, it won''t work
//becuase Ball.h uses Paddle, so i moved paddle above ball.h
class CBall;
class CPaddle;
#include "Ball.h"
#include "Paddle.h"
CBall Ball;
CPaddle Paddle;
//like this:
class CBall;
class CPaddle;
CPaddle Paddle;
#include "Ball.h"
#include "Paddle.h"
CBall Ball;
but now it says
D:\Pong\ddex4.cpp(123) : error C2079: ''Paddle'' uses undefined class ''CPaddle''
I understand why it says this, but is there any way around it? Should i just take out the part in Ball.h that uses the isntance of CPaddle?
t2sherm ô¿ô
//becuase Ball.h uses Paddle, so i moved paddle above ball.h
class CBall;
class CPaddle;
#include "Ball.h"
#include "Paddle.h"
CBall Ball;
CPaddle Paddle;
//like this:
class CBall;
class CPaddle;
CPaddle Paddle;
#include "Ball.h"
#include "Paddle.h"
CBall Ball;
but now it says
D:\Pong\ddex4.cpp(123) : error C2079: ''Paddle'' uses undefined class ''CPaddle''
I understand why it says this, but is there any way around it? Should i just take out the part in Ball.h that uses the isntance of CPaddle?
t2sherm ô¿ô
t2sherm ô¿ô
You need to add ''class CPaddle;'' in front of the header definition for class CPaddle itself. IE
I ran across that the other day.
class CPaddle;
class CPaddle
{
public:
SomeFunc();
private:
CPaddle NotherFunc();
{
I ran across that the other day.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement