help with inheritance

for sum reason i keep getting a bunch of errors, in format of inheritance which to me is correct. i followed straight from the book. Can someone please help me?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// snake class inheriting from class texture and collisionDetection
class Snake : public class Texture, public class CollisionDetection
{
    int snakePos;

    public:
        void drawSnake();
        void setSnakePos();
        void eatFruit();

};

// fruits class inheriting public members of class texture
class Fruits : public class Texture
{
    public:
    void drawFruit();
    void setFruitColor();
    void randFruitPos();
};

// map class inheriting protected and public members of class texture
class Map : protected Texture
{
    public:
    void drawSurface();
    void drawBorders();
    void drawCubes(double x, double y, double z);
    void drawObstacles();
};

class Texture
{
    GLuint snakeTexture[];
    GLuint fruitTexture[];
    GLuint gridTexture[];

protected:
        GLuint loadTexture();
        GLuint change3DEnvironment();
public:

    friend GLuint setSnakeTexture();
    friend GLuint setgridTexture();
    friend GLuint setFruitTexture();

};

class CollisionDetection : public class Map, public class Fruits
{
    void snakeNObstacle();
    void snakeNCubes();
    void snakeNFruits();
};



errors:
||=== Build: Debug in project c++ (compiler: GNU GCC Compiler) ===|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|75|error: expected class-name before 'class'|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|75|error: expected '{' before 'class'|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|75|error: expected unqualified-id before ',' token|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|75|error: expected unqualified-id before 'public'|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|87|error: expected class-name before 'class'|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|87|error: expected '{' before 'class'|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|93|error: multiple types in one declaration|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|105|error: redefinition of 'class Texture'|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|87|error: previous definition of 'class Texture'|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|122|error: expected class-name before 'class'|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|122|error: expected '{' before 'class'|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|122|error: expected unqualified-id before ',' token|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|122|error: expected unqualified-id before 'public'|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.cpp|7|error: aggregate 'Snake Snakes' has incomplete type and cannot be defined|
||=== Build failed: 14 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
You need to remove the "class" keyword from the classes you inherit from.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// snake class inheriting from class texture and collisionDetection
class Snake : public Texture, public CollisionDetection
{
    int snakePos;

    public:
        void drawSnake();
        void setSnakePos();
        void eatFruit();

};

// fruits class inheriting public members of class texture
class Fruits : public Texture
{
    public:
    void drawFruit();
    void setFruitColor();
    void randFruitPos();
};

// map class inheriting protected and public members of class texture
class Map : protected Texture
{
    public:
    void drawSurface();
    void drawBorders();
    void drawCubes(double x, double y, double z);
    void drawObstacles();
};

class Texture
{
    GLuint snakeTexture[];
    GLuint fruitTexture[];
    GLuint gridTexture[];

protected:
        GLuint loadTexture();
        GLuint change3DEnvironment();
public:

    friend GLuint setSnakeTexture();
    friend GLuint setgridTexture();
    friend GLuint setFruitTexture();

};

class CollisionDetection : public Map, public Fruits
{
    void snakeNObstacle();
    void snakeNCubes();
    void snakeNFruits();
};


You're also declaring empty arrays as class data members. That's not going to work out for you. Use a pointer instead. C++ isn't Java, you really need to learn it before you start messing with OpenGL.
thanks alot.. its a school project, im not supposed to implement any of these functions until i kno how to... i tried that before.. i get this:

||=== Build: Debug in project c++ (compiler: GNU GCC Compiler) ===|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|75|error: expected class-name before ',' token|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|76|error: expected class-name before '{' token|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|88|error: expected class-name before '{' token|
C:\Users\Juice\Documents\C++ Assignments\project c++\main.h|97|error: expected class-name before '{' token|
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 4 second(s)) ===|
Move your Texture class (lines 32 - 47) in between lines 1 and 2.
xisman right before you suggested this.. i changed the positions of the classes.. all the base classes i put them at the top.. texture was first in this list.. i went down to two errors.. both saying this "expected class-name before '{' token|".. now i tried your suggestion n now i came up with 8 errors saying the same thing.. its funny im tryin to figure it out.. ca you?
Unless you post your current code, and the actual errors you're having, I'm in the dark.
Topic archived. No new replies allowed.