Advertisement

prototyping classes?

Started by August 02, 2000 09:10 AM
3 comments, last by t2sherm 24 years, 4 months ago
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 ô¿ô
yep... you just put:
    class CBall;//orclass CPaddle;    

Advertisement
//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 ô¿ô
t2sherm ô¿ô
You need to add ''class CPaddle;'' in front of the header definition for class CPaddle itself. IE

class CPaddle;

class CPaddle
{
public:
SomeFunc();
private:
CPaddle NotherFunc();
{


I ran across that the other day.
try something like this:


class CBall;
class CPaddle;

#include "Paddle.h"

CPaddle Paddle;
#include "Ball.h"

CBall Ball;



You know, I never wanted to be a programmer...

Alexandre Moura

Edited by - alexmoura on August 2, 2000 3:59:56 PM

This topic is closed to new replies.

Advertisement