0

I have an abstract base Object class and two derived classes from it: Paddle and Ball. Paddle's constructor accepts as a parameter a pointer to Ball so that i can get its position to calculate the paddle movement:

Paddle::Paddle(Vec location, Vec size, float AIspeed, Ball* prtBall)
    :  Object(location, size)
{
    /* ... */
    gameBall = ptrBall;
}

IntelliSense does not flag this as invalid, but whenever I compile the code, VS2013 unexpectedly throws the following errors:

1>\object\paddle.h(8): error C2061: syntax error : identifier 'Ball'
1>\object\paddle.h(43): error C2143: syntax error : missing ';' before '*'
1>\object\paddle.h(43): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>\object\paddle.h(18): error C2065: 'gameBall' : undeclared identifier
1>\object\paddle.h(18): error C2065: 'ptrBall' : undeclared identifier
1>\object\paddle.h(30): error C2065: 'gameBall' : undeclared identifier

The first two are particularly interesting... From the looks of it, the compiler is not recognizing that Ball* is a type. Line 8 is the one above and these are lines 40-44:

private:
    void Foo();

    Ball* gameBall;
    float bar;

At first I was thinking that I forgot to include Ball's definition in the file paddle.h. But this is not the case. Is what I`m doing correct or is there a flaw currently overlooked?

rlam12
  • 603
  • 5
  • 16
  • Can you please create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve) and show us? – Some programmer dude Jan 24 '15 at 19:31
  • Sure @JoachimPileborg working on it right now :) – rlam12 Jan 24 '15 at 19:33
  • The compiler doesn't recognize the symbol `Ball`. Did you forget to #include the .h file where `Ball` is defined in `paddle.h`? – MrEricSir Jan 24 '15 at 19:40
  • Does `ball.h` also `#define `? Circular includes cause problems, even with include guards. Perhaps you need to use a forward-declaration instead of an include. – Ben Voigt Jan 24 '15 at 19:44
  • Probably a duplicate of http://stackoverflow.com/q/14909997/103167 and http://stackoverflow.com/q/6554492/103167 – Ben Voigt Jan 24 '15 at 19:46
  • Indeed, it was a circular include @BenVoigt Paddle.h was not including directly Ball.h, but they were mutually included upper on my #include stack, noticed that when working on a reproducible example. – rlam12 Jan 24 '15 at 20:46

1 Answers1

1

Yes, provided the access rights to the sibling's data member or method is public.

Siblings don't have access to other sibling's private or protected data methods and data members.

You could create a virtual method in the Parent class. One sibling can then go through the parent (via the function) to get the data; but then as I have learned, life is better when you talk to your sibling directly rather than going through the parent. :-)

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154