By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,341 Members | 1,395 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,341 IT Pros & Developers. It's quick & easy.

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

P: 20
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:
Expand|Select|Wrap|Line Numbers
  1.  
  2. #ifndef RANGE_H_INCLUDED
  3. #define RANGE_H_INCLUDED
  4. #include "grid.h"   //for type: presenceGrid
  5. #include <vector>
  6. #include "AreaMap.h"
  7.  
  8. class Range
  9. {
  10.     private:
  11.     struct location {int pos_x; int pos_y;};
  12.     int x_size, y_size;                     
  13.     AreaMap& r_map;   //LINE 16
  14.     std::vector<location> presences;        
  15.     presenceGrid map;                      
  16.     location start;                        
  17.  
  18.     void addCell(location);
  19.     void grow (int size);                          
  20.     location pickRandomCell();
  21.     location pickCellOnRange();
  22.     location findNeighbourCell(location);
  23.     bool outsideDomain (location);
  24.  
  25.  
  26.     public:
  27.  
  28.     Range(AreaMap&);
  29.     ~Range() {}
  30.     presenceGrid sample(int size) {grow(size); return map;}
  31.     friend class TotalAreaMap;                 
  32. };                                         
  33. #endif // RANGE_H_INCLUDED
and the AreaMap class:
Expand|Select|Wrap|Line Numbers
  1. #ifndef MAP_H_INCLUDED
  2. #define MAP_H_INCLUDED
  3.  
  4. #include <vector>
  5. #include <string>
  6.  
  7. #include "Species.h"
  8. #include "RangeProp.h"
  9. #include "Envar.h"
  10. /*Holds a map showing land and water of the underlying
  11. domain (continent) where the species are distributed
  12. */
  13.  
  14. class AreaMap
  15. {
  16.     public:
  17.         AreaMap(){}
  18.         ~AreaMap(){}
  19.         void loadSQSfile();
  20.         bool land(int y, int x){return (bool) domain[y][x];}
  21.         int getXsize(){return x_size;}
  22.         int getYsize(){return y_size;}
  23.         float getXllCenter(){return xllcenter;}
  24.         float getYllCenter(){return yllcenter;}
  25.         int area();
  26.  
  27.     private:
  28.         std::vector<std::vector<int> > domain;
  29.         int x_size;
  30.         int y_size;
  31.         float xllcenter;
  32.         float yllcenter;
  33.  
  34.     friend class Species;
  35.     friend class EnVar;
  36.     friend class RangeProp;
  37.  
  38. };
  39.  
  40.  
  41. #endif // MAP_H_INCLUDED
  42.  
Maybe a fresh (expert) eye can tell the mistake straight away, thanks!

Mike
Oct 16 '07 #1
Share this Question
Share on Google+
6 Replies


Banfa
Expert Mod 5K+
P: 8,916
Expand|Select|Wrap|Line Numbers
  1. #ifndef MAP_H_INCLUDED
Does MAP_H_INCLUDED correlate with the inclusion protection in the C++ header <map> on your system? Are you including this header anywhere?
Oct 16 '07 #2

P: 20
No, as far as I can tell, the <map> file is guarded by a
Expand|Select|Wrap|Line Numbers
  1.  #ifndef MAP_H
tag, and I do not use the STL container Map anywhere. Changing the guard token to
Expand|Select|Wrap|Line Numbers
  1. #ifndef AREAMAP_H_INCLUDED
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?
Oct 17 '07 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
This version of your code compiles with only one warning. I have commented that line.
Expand|Select|Wrap|Line Numbers
  1. class presenceGrid
  2. {
  3. };
  4.  
  5.  
  6. class AreaMap
  7. {
  8.     public:
  9.         AreaMap(){}
  10.         ~AreaMap(){}
  11.         void loadSQSfile();
  12.         bool land(int y, int x){return (bool) domain[y][x];}  //WFC: forcing int to bool here
  13.         int getXsize(){return x_size;}
  14.         int getYsize(){return y_size;}
  15.         float getXllCenter(){return xllcenter;}
  16.         float getYllCenter(){return yllcenter;}
  17.         int area();
  18.  
  19.     private:
  20.         std::vector<std::vector<int> > domain;
  21.         int x_size;
  22.         int y_size;
  23.         float xllcenter;
  24.         float yllcenter;
  25.  
  26.     friend class Species;
  27.     friend class EnVar;
  28.     friend class RangeProp;
  29.  
  30. };
  31.  
  32. class Range
  33. {
  34.     private:
  35.     struct location {int pos_x; int pos_y;};
  36.     int x_size, y_size;                     
  37.     AreaMap& r_map;   //LINE 16
  38.     std::vector<location> presences;        
  39.     presenceGrid map;                      
  40.     location start;                        
  41.  
  42.     void addCell(location);
  43.     void grow (int size);                          
  44.     location pickRandomCell();
  45.     location pickCellOnRange();
  46.     location findNeighbourCell(location);
  47.     bool outsideDomain (location);
  48.  
  49.  
  50.     public:
  51.  
  52.     Range(AreaMap&);
  53.     ~Range() {}
  54.     presenceGrid sample(int size) {grow(size); return map;}
  55.     friend class TotalAreaMap;                 
  56. };  
  57. int main()
  58. {
  59.  
  60. }
  61.  
There might an some weird error in your included header files. Like the #ifndef symbol has been used by more than one header.
Oct 17 '07 #4

P: 20
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:
Expand|Select|Wrap|Line Numbers
  1. #ifndef AREAMAP_H_INCLUDED
  2. #define AREAMAP_H_INCLUDED
  3.  
  4. #include <vector>
  5. #include <string>
  6.  
  7.  
  8. class AreaMap
  9. {
  10.     public:
  11.         AreaMap(){}
  12.         ~AreaMap(){}
  13.         void loadSQSfile();
  14.         bool land(int y, int x){return (bool) domain[y][x];}
  15.         int getXsize(){return x_size;}
  16.         int getYsize(){return y_size;}
  17.         float getXllCenter(){return xllcenter;}
  18.         float getYllCenter(){return yllcenter;}
  19.         int area();
  20.  
  21.     private:
  22.         std::vector<std::vector<int> > domain;
  23.         int x_size;
  24.         int y_size;
  25.         float xllcenter;
  26.         float yllcenter;
  27.  
  28. };
  29.                                 //Moved all of this down here
  30. #include "Species.h"                         
  31. #include "RangeProp.h"
  32. #include "Envar.h"
  33.  
  34. AreaMap::friend class Species;
  35. AreaMap::friend class EnVar;
  36. AreaMap::friend class RangeProp;
  37.  
  38. #endif // AREAMAP_H_INCLUDED
Oct 17 '07 #5

weaknessforcats
Expert Mod 5K+
P: 9,197
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:
Expand|Select|Wrap|Line Numbers
  1. class MyClass;     //forward reference
  2.  
  3. class Node
  4. {
  5.       private:
  6.          MyClass& data;
  7. //etc...
  8. };
  9.  
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.
Oct 17 '07 #6

P: 20
Thanks!
That solved my problem :)
Oct 18 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.