ISO C++ forbids declaration of 'Areamap' with no type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mkborregaard
    New Member
    • Sep 2007
    • 20

    ISO C++ forbids declaration of 'Areamap' with no type

    Hi,
    I am getting an error message from MinGW that I just cannot figure what causes.
    The error message is:
    "Line 16: ISO C++ forbids declaration of 'AreaMap' with no type"
    My code is:[CODE=cpp]

    #ifndef RANGE_H_INCLUDE D
    #define RANGE_H_INCLUDE D
    #include "grid.h" //for type: presenceGrid
    #include <vector>
    #include "AreaMap.h"

    class Range
    {
    private:
    struct location {int pos_x; int pos_y;};
    int x_size, y_size;
    AreaMap& r_map; //LINE 16
    std::vector<loc ation> presences;
    presenceGrid map;
    location start;

    void addCell(locatio n);
    void grow (int size);
    location pickRandomCell( );
    location pickCellOnRange ();
    location findNeighbourCe ll(location);
    bool outsideDomain (location);


    public:

    Range(AreaMap&) ;
    ~Range() {}
    presenceGrid sample(int size) {grow(size); return map;}
    friend class TotalAreaMap;
    };
    #endif // RANGE_H_INCLUDE D[/CODE]
    and the AreaMap class:
    [CODE=cpp]
    #ifndef MAP_H_INCLUDED
    #define MAP_H_INCLUDED

    #include <vector>
    #include <string>

    #include "Species.h"
    #include "RangeProp. h"
    #include "Envar.h"
    /*Holds a map showing land and water of the underlying
    domain (continent) where the species are distributed
    */

    class AreaMap
    {
    public:
    AreaMap(){}
    ~AreaMap(){}
    void loadSQSfile();
    bool land(int y, int x){return (bool) domain[y][x];}
    int getXsize(){retu rn x_size;}
    int getYsize(){retu rn y_size;}
    float getXllCenter(){ return xllcenter;}
    float getYllCenter(){ return yllcenter;}
    int area();

    private:
    std::vector<std ::vector<int> > domain;
    int x_size;
    int y_size;
    float xllcenter;
    float yllcenter;

    friend class Species;
    friend class EnVar;
    friend class RangeProp;

    };


    #endif // MAP_H_INCLUDED
    [/CODE]
    Maybe a fresh (expert) eye can tell the mistake straight away, thanks!

    Mike
    Last edited by Banfa; Oct 16 '07, 10:36 PM. Reason: Added =cpp to make the C++ code tags
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    [code=cpp]#ifndef MAP_H_INCLUDED[/code]Does MAP_H_INCLUDED correlate with the inclusion protection in the C++ header <map> on your system? Are you including this header anywhere?

    Comment

    • mkborregaard
      New Member
      • Sep 2007
      • 20

      #3
      No, as far as I can tell, the <map> file is guarded by a
      [CODE=cpp] #ifndef MAP_H[/CODE] tag, and I do not use the STL container Map anywhere. Changing the guard token to [CODE=cpp]#ifndef AREAMAP_H_INCLU DED[/CODE] does not change the problem.
      The AreaMap class used to be called Map, but I thought it might collide, so I changed the name, and created a completely new project and copied all my code files into that, to make sure no old dependencies were messing up.
      By the way, I also updated to the newest version of MinGW (and my Code::blocks editor).
      The problem persists.
      Any other suggestions as to what it might be?

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        This version of your code compiles with only one warning. I have commented that line.
        [code=cpp]
        class presenceGrid
        {
        };


        class AreaMap
        {
        public:
        AreaMap(){}
        ~AreaMap(){}
        void loadSQSfile();
        bool land(int y, int x){return (bool) domain[y][x];} //WFC: forcing int to bool here
        int getXsize(){retu rn x_size;}
        int getYsize(){retu rn y_size;}
        float getXllCenter(){ return xllcenter;}
        float getYllCenter(){ return yllcenter;}
        int area();

        private:
        std::vector<std ::vector<int> > domain;
        int x_size;
        int y_size;
        float xllcenter;
        float yllcenter;

        friend class Species;
        friend class EnVar;
        friend class RangeProp;

        };

        class Range
        {
        private:
        struct location {int pos_x; int pos_y;};
        int x_size, y_size;
        AreaMap& r_map; //LINE 16
        std::vector<loc ation> presences;
        presenceGrid map;
        location start;

        void addCell(locatio n);
        void grow (int size);
        location pickRandomCell( );
        location pickCellOnRange ();
        location findNeighbourCe ll(location);
        bool outsideDomain (location);


        public:

        Range(AreaMap&) ;
        ~Range() {}
        presenceGrid sample(int size) {grow(size); return map;}
        friend class TotalAreaMap;
        };
        int main()
        {

        }
        [/code]

        There might an some weird error in your included header files. Like the #ifndef symbol has been used by more than one header.

        Comment

        • mkborregaard
          New Member
          • Sep 2007
          • 20

          #5
          You're right, that compiles without problems on my system too, which means that noone on the forum had any chance to find the error, sorry.
          The error does indeed seem to be with the #includes - the problem is generated when the three friend classes in turn includes AreaMap, because each class contains a reference to AreaMap - and class AreaMap has not yet been declared at that point. I must be doing something wrong with the includes; how does one deal with mutual includes?
          I have dealt with the problem now like this:
          [CODE=cpp]#ifndef AREAMAP_H_INCLU DED
          #define AREAMAP_H_INCLU DED

          #include <vector>
          #include <string>


          class AreaMap
          {
          public:
          AreaMap(){}
          ~AreaMap(){}
          void loadSQSfile();
          bool land(int y, int x){return (bool) domain[y][x];}
          int getXsize(){retu rn x_size;}
          int getYsize(){retu rn y_size;}
          float getXllCenter(){ return xllcenter;}
          float getYllCenter(){ return yllcenter;}
          int area();

          private:
          std::vector<std ::vector<int> > domain;
          int x_size;
          int y_size;
          float xllcenter;
          float yllcenter;

          };
          //Moved all of this down here
          #include "Species.h"
          #include "RangeProp. h"
          #include "Envar.h"

          AreaMap::friend class Species;
          AreaMap::friend class EnVar;
          AreaMap::friend class RangeProp;

          #endif // AREAMAP_H_INCLU DED[/CODE]

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Originally posted by mkborregaard
            the problem is generated when the three friend classes in turn includes AreaMap, because each class contains a reference to AreaMap - and class AreaMap has not yet been declared at that point.
            You can use an forward reference:
            [code=cpp]
            class MyClass; //forward reference

            class Node
            {
            private:
            MyClass& data;
            //etc...
            };
            [/code]

            The forward reference is kinda like a prototype for a class (or struct). It provides enough information for the compiler to allow a MyClass* or MyClass& but that's about it. If you use the Myclass at all, like a MyClass member of Node, then the compiler needs to see if there is a default constructor and that will require posting the whole class.

            Comment

            • mkborregaard
              New Member
              • Sep 2007
              • 20

              #7
              Thanks!
              That solved my problem :)

              Comment

              Working...