类定义中的错误C2143和C4430;

时间:2015-04-04 18:21:41

标签: c++ class pointers reference syntax-error

我遇到了问题 当我在类Organism中的类World上声明指针时,我得到C2143C4430错误。当我评论这一行时,所有这些错误都消失了......
我不知道如何声明对类World的引用。救命!引导我,在那里我可以找到解决方案。

1>  Touching "Debug\Gra.unsuccessfulbuild".
1>ClCompile:
1>  main.cpp
1>g:\projekt\gra\gra\organism.h(14): error C2143: syntax error : missing ';' before '*'
1>g:\projekt\gra\gra\organism.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>g:\projekt\gra\gra\organism.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>  World.cpp
1>g:\projekt\gra\gra\organism.h(14): error C2143: syntax error : missing ';' before '*'
1>g:\projekt\gra\gra\organism.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>g:\projekt\gra\gra\organism.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>  Human.cpp
1>g:\projekt\gra\gra\plant.h(5): error C2504: 'Organism' : base class undefined
1>  Generating Code...
1>  Compiling...
1>  Plant.cpp
1>  Generating Code...
1>
1>Build FAILED.

档案Worl​​d.h:

#pragma once
#include "Plant.h"

class World {    
public:
    World(int x = 15, int y = 15);
    ~World();
    void nextTurn(); // next turn
    void printWorld(); // print world in ASCII
    void printStats(); // print descripction about obejcts in the world
    friend class Organism;

protected:
    int x, y; // size of the world
    int orgCnt; // organism counter
    Organism **coord; // coordinates of the world
    int round; // equivalent of time in the world;
};

文件Organism.h:

#pragma once    
#include "World.h"

class Organism {
public:
    virtual bool action() = 0;
    virtual void move() = 0;
    virtual bool collision() = 0;   
    virtual void show() = 0;
    virtual void insert() = 0;

protected:
    World *w; //---error here--- When i comment this line, everyting is ok.
    int power;
    int activity;
    int x, y;
};

文件Human.h

#pragma once    
#include "Organism.h"

class Human: public Organism {    
public:
    Human();
    ~Human();
    virtual bool action();
    virtual bool collision();
    virtual void move();
    virtual void show();
    virtual void insert();
};

0 个答案:

没有答案