Errors in my code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nemisis
    New Member
    • May 2007
    • 61

    Errors in my code

    Fish.h

    [CODE=cpp]

    #ifndef FISH_H
    #define FISH_H

    #include <iostream>
    #include <vector>

    #include "Point.h"

    class Fish : public Animal
    {

    public:

    Fish();
    Fish(const int fish_breed_time );
    inline ~Fish() {decrement_num_ fish_current(); delete *this; };
    Point *vector PossibleSurroun dings(all_surro undings); //based on edibility of cell's animal and surroundings
    void JustEaten();
    void ReduceGestation Time();
    static int increment_num_f ish_current();
    static int decrement_num_f ish_current();

    private:

    std::string taste; //options are bitter and sweet
    int fish_breed_time ;
    int fish_gestation_ time;
    static int num_fish_curren t;
    Point *vector all_surrounding s;

    };

    #endif
    [/CODE]

    Fish.cc

    [CODE=cpp]
    #include "Fish.h"

    using namespace std;

    Fish::Fish( fish_breed_time )
    {
    int fish_gestation_ time = fish_breed_time ;
    increment_num_f ish_current();

    }


    Point *vector Fish::PossibleS urroundings(all _surroundings)
    {

    for (int i=0; i<all_surroundi ngs.length; i++)
    {

    CheckCell


    }



    }


    void Fish::JustEaten ()
    {
    ~Fish();
    }

    void Fish::ReduceGes tationTime()
    {
    fish_gestation_ time--;
    }


    static int Fish::increment _num_fish_curre nt()
    {
    num_fish_curren t++;
    return num_fish_curren t;

    }

    static int Fish::decrement _num_fish_curre nt()
    {
    num_fish_curren t--;
    return num_fish_curren t;

    }

    [/CODE]

    errors -

    1)Fish.h|10|err or: expected class-name before '{' token|
    2)Fish.h|17|err or: expected `;' before "PossibleSurrou ndings"|
    3)Fish.h|29|err or: expected `;' before "all_surroundin gs"|
    4)Fish.h||In destructor `Fish::~Fish()' :|
    5)Fish.h|16|err or: type `class Fish' argument given to `delete', expected pointer|
    6)Fish.cc|6|err or: invalid function declaration|
    7)Fish.cc|13|er ror: expected initializer before "Fish"|
    8)Fish.cc||In member function `void Fish::JustEaten ()':|
    9)Fish.cc|31|er ror: no match for 'operator~' in '~Fish()'|
    /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/ios_base.h|104| note: candidates are: std::_Ios_Fmtfl ags std::operator~( std::_Ios_Fmtfl ags)|
    /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/ios_base.h|144| note: std::_Ios_Openm ode std::operator~( std::_Ios_Openm ode)|
    /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/ios_base.h|182| note: std::_Ios_Iosta te std::operator~( std::_Ios_Iosta te)|
    10)Fish.cc|41|e rror: cannot declare member function `static int Fish::increment _num_fish_curre nt()' to have static linkage|
    11)Fish.cc|48|e rror: cannot declare member function `static int Fish::decrement _num_fish_curre nt()' to have static linkage|
    ||=== Build finished: 9 errors, 0 warnings ===|
  • oler1s
    Recognized Expert Contributor
    • Aug 2007
    • 671

    #2
    I fail to see what your question is.

    Comment

    • RRick
      Recognized Expert Contributor
      • Feb 2007
      • 463

      #3
      You have not included any information about Animal. The compiler needs the class Animal info to compile line 10.

      That should get you started.

      Comment

      • nemisis
        New Member
        • May 2007
        • 61

        #4
        ok so i cleared whatever i could but am stuck with 2 major errors only

        Point.h
        [code=cpp]
        /**
        * A Point struct stores the coordinates x, y of a 2D location
        */
        #ifndef POINT_H
        #define POINT_H

        typedef enum
        {
        SWEET,
        BITTER,
        SALTY
        } Taste;

        struct Point
        {
        int x, y;
        inline Point(int X = 0, int Y = 0): x(X), y(Y){}
        };

        struct Properties
        {
        Point my_point;
        Taste my_taste;
        inline Properties(Poin t mypoint(0,0),Ta ste mytaste = SALTY): my_point(mypoin t), my_taste(mytast e){}
        };

        #endif

        [/code]

        Animal.h
        [code=cpp]
        #ifndef ANIMAL_H
        #define ANIMAL_H

        #include <iostream>
        #include <vector>
        #include <string>

        /* User Defined Header Files */

        #include "Point.h"

        /* Animal is an abstract base class that contains a pointer to either a shark or a fish. */

        using namespace std;

        class Animal
        {
        public:

        inline Animal(){};
        Taste getTaste();
        bool hasRun();
        void resetState();
        inline virtual ~Animal(){};
        virtual int run(vector <Properties> all_surrounding s)=0;
        virtual vector <Properties> possibleSurroun dings(vector <Properties> all_surrounding s)=0;
        virtual Properties decide (vector <Properties> possible_surrou ndings)const =0; //
        virtual bool gestate()=0;


        private:

        vector<Point> possible_surrou ndings;
        vector<Point> all_surrounding s;
        Taste my_taste;
        bool run_state;
        };

        #endif
        [/code]

        Animal.cc
        [code=cpp]

        #include <iostream>
        #include <sstream>
        #include <string>

        // User defined headers
        #include "Animal.h"



        bool Animal::hasRun( )
        {
        return run_state;
        }

        void Animal::resetSt ate()
        {
        run_state = false;
        }

        Taste Animal::getTast e()
        {
        return my_taste;
        }
        [/code]

        FIsh.h
        [code=cpp]
        #ifndef FISH_H
        #define FISH_H

        #include <iostream>
        #include <vector>
        #include <string>

        #include "Animal.h"

        using namespace std;

        class Fish : public Animal
        {

        public:
        Fish(const int fish_breed_time );
        virtual ~Fish();
        vector <Properties> possibleSurroun dings(vector<Pr operties> all_surrounding s); //based on edibility of cell's animal and surroundings
        bool gestate();
        void run(vector <Properties>) const;
        Properties run(vector <Properties> all_surrounding s, Properties current_point);
        Properties decide (vector <Properties> possible_surrou ndings, Properties current_point); //Randonly picks one point and returns it to Cell
        void resetGestationT ime();
        Properties birthLocation (vector <Properties> all_surrounding s, Properties current_point);

        private:

        static Taste my_taste;
        int fish_breed_time ;
        int fish_gestation_ time;
        static int num_fish_curren t;
        };

        #endif

        [/code]

        Fish.cc
        [code=cpp]
        #include <iostream>
        #include <sstream>
        #include <string>

        //User defined headers
        #include "Fish.h"


        using namespace std;
        static int num_fish_curren t = 0;
        static Taste my_taste = SWEET;


        Fish::Fish(cons t int fish_breed_time )
        {
        int fish_gestation_ time = fish_breed_time ;
        num_fish_curren t++;
        Animal::resetSt ate();
        }


        Fish::~Fish()
        {
        num_fish_curren t--;
        delete this;
        }

        bool Fish::gestate()
        {
        if (fish_gestation _time <= 0) return true;
        else return false;
        }

        void Fish::resetGest ationTime()
        {
        fish_gestation_ time=fish_breed _time;

        }

        vector <Properties> Fish::possibleS urroundings(vec tor <Properties> all_surrounding s)
        {
        vector <Properties> possible_surrou ndings;
        for (int i=0; i < all_surrounding s.size(); i++)
        {
        if (all_surroundin gs[i].my_taste == SALTY) possible_surrou ndings.push_bac k(all_surroundi ngs[i]);

        }
        return possible_surrou ndings;
        }


        Properties Fish::decide (vector <Properties> possible_surrou ndings, Properties current_point)
        {

        Properties destination;
        if (possible_surro undings.size() == 0)
        {
        destination = current_point;
        }
        else
        {
        srand(time(NULL )); //reset seed
        destination = possible_surrou ndings[rand() % (possible_surro undings.size())]; //randomly pick destination
        }
        return destination;
        }

        Properties Fish::run(vecto r <Properties> all_surrounding s, Properties current_point)
        {
        Properties destination;

        if (gestate() == true)
        {
        destination = birthLocation(a ll_surroundings , current_point);
        }

        else
        {
        vector<Properti es> possible_surrou ndings = possibleSurroun dings(all_surro undings);
        destination = decide (possible_surro undings, current_point);
        }
        return destination;
        }


        Properties Fish::birthLoca tion (vector <Properties> all_surrounding s, Properties current_point)
        {
        Properties destination=cur rent_point;

        for (int i=0; i<all_surroundi ngs.size(); i++)
        {
        if (all_surroundin gs[i].my_taste == SALTY)
        {
        destination = all_surrounding s[i];
        }
        }
        return destination;
        }
        [/code]

        and this is where i am stuck:

        1)Point.h|24|er ror: expected `,' or `...' before '(' token
        Point.h||In constructor `Properties::Pr operties(Point) ':

        2)Point.h|24|er ror: `mytaste' was not declared in this scope
        Fish.cc||In member function `Properties Fish::decide(st d::vector<Prope rties, std::allocator< Properties> >, Properties)':

        3)Fish.cc|55|er ror: no matching function for call to `Properties::Pr operties()'
        Point.h|21|note : candidates are: Properties::Pro perties(const Properties&)
        Point.h|24|note : Properties::Pro perties(Point)
        Fish.cc||In member function `Properties Fish::run(std:: vector<Properti es, std::allocator< Properties> >, Properties)':

        4)Fish.cc|70|er ror: no matching function for call to `Properties::Pr operties()'
        Point.h|21|note : candidates are: Properties::Pro perties(const Properties&)
        Point.h|24|note : Properties::Pro perties(Point)

        ||=== Build finished: 4 errors, 0 warnings ===

        plz help clear them. thanks

        Comment

        • nemisis
          New Member
          • May 2007
          • 61

          #5
          ummmm nevermind i got it; was missing a '=' in this line in Point.h

          inline Properties(Poin t mypoint=(0,0),T aste mytaste = SALTY): my_point(mypoin t), my_taste(mytast e){}

          but i ll post more after i compile the whole program.

          Cheers

          Comment

          Working...