473,699 Members | 2,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

20 New Member
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
6 6019
Banfa
9,065 Recognized Expert Moderator Expert
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
mkborregaard
20 New Member
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
9,208 Recognized Expert Moderator Expert
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
mkborregaard
20 New Member
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
9,208 Recognized Expert Moderator Expert
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
mkborregaard
20 New Member
Thanks!
That solved my problem :)
Oct 18 '07 #7

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

Similar topics

2
2602
by: Henrik S. Hansen | last post by:
I'm new to C++, and cannot figure out why this won't compile: std::map<std::string, int> tst; tst = 1; int main() { /*...*/ } It gives me: error: ISO C++ forbids declaration of `tst' with no type
5
2745
by: j0mbolar | last post by:
operator = (const char *string) { if(m_string) { free(m_string); m_string = 0; } if(string) { m_string = strdup(string); } }
4
35023
by: Juhan Voolaid | last post by:
Hi I need help here. When i compile my program, i get this error: $ make g++ -c -Wall inf2_functions.cpp -o inf2_functions.o inf2_classes.h:6: error: ISO C++ forbids declaration of ‘vector’ with no type inf2_classes.h:6: error: expected ‘;’ before ‘<’ token make: *** Error 1
3
50486
by: gamehack | last post by:
Hi all, Here's the error which I'm getting when trying to compile some code: boxmanager.h:16: error: ISO C++ forbids declaration of 'vector' with no type boxmanager.h:16: error: expected ';' before '<' token boxmanager.h:17: error: ISO C++ forbids declaration of 'vector' with no type
1
7334
by: eric | last post by:
hello i'm trying to implement some functionality whereby an algorithm in a base template class relies on a function pointer supplied by a derived template class. the types are only specified by the client (caller) of the derived class. i got it working under visual studio 2003/2005 but gcc 4.1.0 compilation fails. here's the smallest subset of the code that shows the error:
7
9426
by: Florian Haag | last post by:
Hello, I'm trying to compile a programme which compiles fine under Linux; I'm trying it with MinGW G++ 3.4.2: Component.h: #ifndef COMPONENT_H_ #define COMPONENT_H_
8
7868
by: aneuryzma | last post by:
Hello, I'm merging an OpenCV app with an Ogre3d app. I'm on a mac, I'm using xCode. When I add #include "openCVApp.h" I got the following error:
6
14720
by: samsneelam | last post by:
Hi.. This is samuel, while doing a program, i encountered this problem.. Let me give you clarity regarding my prob.. I am having two files .. one is mpcplib.h it contains the follwing declerations.... #include <queue> #include <vector> #include <string> class database { queue<delayTP> delayThrouput;
10
4331
by: tvnaidu | last post by:
I am using Three pthread functions below, I got ISO error, then I declared int variable called val123, then I assigned, but still I am getting error, any idea?. also I included pthread.h. compiling in Linux with GCC. pthread_cond_signal(&(receiverConf->receive_q_cond)); pthread_cond_destroy(&(receiverConf->receive_q_cond)); pthread_mutex_destroy(&(receiverConf->receive_q_lock)); Main.cpp:545: ISO C++ forbids declaration of ` ...
0
8612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.