尽管包含了类,但是c ++声明错误

时间:2014-03-12 22:58:17

标签: c++ class inheritance

我已经阅读了大量类似的问题,但我仍然无法弄明白。当我尝试编译时,我在QT创建者中遇到错误:"网格尚未声明"尽管我在bunny类中包含了Grid类标题,显示了此错误。这是我的代码:

(错误产生于功能行" void becomeVampire(Bunny *&,int&,Grid&);",如果从第一个算起来,则为第五个( BUNNY)类,以及函数" void convertNeighbourToVampire(Bunny * const,int&,Grid&);"这是第一个从下到上:这两个函数都使用对Grid类的引用其中一个参数)

#ifndef BUNNY_H
#define BUNNY_H

#include <conio.h>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <windows.h>


#include "Position.h"
#include "Grid.h"

int GetRandom(int x);

class Bunny:public Position
{

private:
    static const std::vector <std::string> F_names;             //all the female names
    static const std::vector <std::string> M_names;             //all the male names
    static const std::vector <std::string> colors;              //all the colors
    bool isMale= GetRandom(2)<1 ? true : false;                 //at creation,bunnies gender is randomly chose//50%chance
    bool isVampire= GetRandom(100)< 2 ? true : false;           //2% chance for birth of vamp bunny
    std::string name;
    std::string color;
    std::string sex;
    std::string vampire;
    int age;
    void Inner(int & TVamps);                                   //use this inside of constructors,assign all needed info to a bunny
    void half(Bunny *&,int &);                                  //halfs the population randomly
    void increaseAge();                                         //called by ageUp() function,increases the age of a particular bunny object
public:
    Bunny * Next;                                               //pointer to next bunny in linked list

    Bunny(int & TVamps);                                        //DEFAULT CONSTRUCTOR
    Bunny(std::string C,int & TVamps);                          //CHILDREN CONSTRUCTOR
    ~Bunny();                                                   //DESTRUCTOR

    //NEXT is self explanatory
    bool isMatureMale() const {if(  (this->age>2) &&(isMale) &&(!isVampire) ){return true;} return false;}
    bool isMatureFemale() const {if(  (age>2) &&( !isMale) &&(!isVampire) ){return true;} return false;}
    bool getIsMale() const {return isMale;}
    std::string getName() const {return name;}
    std::string getColor() const {return color;}
    std::string getSex()const {return sex;}
    std::string getVampire() const{return vampire;}
    bool getIsVampire() const {return isVampire;}
    int getAge() const {return age;}

    void makeVampire(int &);                                        //make certain bunny a vampire
    bool isEmpty(Bunny *) const;                                    //is bunny colony empty
    void ageUp(Bunny *);                                            //increase the populations age by 1
    void insertBunny(Bunny *,Bunny *&, int &,int &);                //add a child,parameters are: head pointer,reference of last pointer,and counter of bunnies and vampires
    void insertFirstBunny(Bunny *&, int &,int &);                   //insert a bunny with no parrent
    void printBunnies(Bunny * , int , int,int) const;               //prints out the whole colony info
    void removeBunny(Bunny *& ,int &, int &);                       //removes old bunnies


    **void becomeVampire(Bunny *& , int &,Grid &);                  //converts bunnies to vampires**
    void FoodShortage(Bunny *& ,int &);                             //kills half of bunnies randomly,takes pointer reference of head pointer as parameter
    void massRabitKull(Bunny *&,int &);                             //when "k" or "K" is pressed,calls the half() function
    bool isArrayOutOfBounds(int x, Bunny const * const temp);        // north-1   south-2   east-3  west-4
    void convertNeighbourToVampire(Bunny * const, int &, Grid &);

};

#endif // BUNNY_H

这是Grid类:

#ifndef GRID_H
#define GRID_H
#include "Position.h"
#include "Bunny.h"

class Grid
{
private:
    char GridField[80][80];
    void renewGrid();                                       //sets all grid positions to '.',called by constructor and updateTheGrid()
public:
    Grid();
    void updateTheGrid(Bunny * const);                      //sets all grid positions to new positions based on new bunny objects linked list
    void printTheGrid() const;                              //prints the grid to the new file
    char getGridField(int,int);                             //returns the character on certain position


};

#endif // GRID_H

和最后一堂课,职位:

#define POSITION_H
#include "Grid.h"

class Position
{
private:
    int row,column;
    char sign;

public:
    Position();
    Position ( int parrentRow,int parrentColumn );
    int getRow() const ;
    int getColumn() const;
    char getSign() const;

};

#endif // POSITION_H

0 个答案:

没有答案