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: -
-
#ifndef RANGE_H_INCLUDED
-
#define RANGE_H_INCLUDED
-
#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<location> presences;
-
presenceGrid map;
-
location start;
-
-
void addCell(location);
-
void grow (int size);
-
location pickRandomCell();
-
location pickCellOnRange();
-
location findNeighbourCell(location);
-
bool outsideDomain (location);
-
-
-
public:
-
-
Range(AreaMap&);
-
~Range() {}
-
presenceGrid sample(int size) {grow(size); return map;}
-
friend class TotalAreaMap;
-
};
-
#endif // RANGE_H_INCLUDED
and the AreaMap class: -
#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(){return x_size;}
-
int getYsize(){return 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
-
Maybe a fresh (expert) eye can tell the mistake straight away, thanks!
Mike
6 6019 Banfa 9,065
Recognized Expert Moderator Expert
Does MAP_H_INCLUDED correlate with the inclusion protection in the C++ header <map> on your system? Are you including this header anywhere?
No, as far as I can tell, the <map> file is guarded by a
tag, and I do not use the STL container Map anywhere. Changing the guard token to - #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?
This version of your code compiles with only one warning. I have commented that line. -
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(){return x_size;}
-
int getYsize(){return 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<location> presences;
-
presenceGrid map;
-
location start;
-
-
void addCell(location);
-
void grow (int size);
-
location pickRandomCell();
-
location pickCellOnRange();
-
location findNeighbourCell(location);
-
bool outsideDomain (location);
-
-
-
public:
-
-
Range(AreaMap&);
-
~Range() {}
-
presenceGrid sample(int size) {grow(size); return map;}
-
friend class TotalAreaMap;
-
};
-
int main()
-
{
-
-
}
-
There might an some weird error in your included header files. Like the #ifndef symbol has been used by more than one header.
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: - #ifndef AREAMAP_H_INCLUDED
-
#define AREAMAP_H_INCLUDED
-
-
#include <vector>
-
#include <string>
-
-
-
class AreaMap
-
{
-
public:
-
AreaMap(){}
-
~AreaMap(){}
-
void loadSQSfile();
-
bool land(int y, int x){return (bool) domain[y][x];}
-
int getXsize(){return x_size;}
-
int getYsize(){return 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_INCLUDED
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: -
class MyClass; //forward reference
-
-
class Node
-
{
-
private:
-
MyClass& data;
-
//etc...
-
};
-
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.
Thanks!
That solved my problem :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
by: j0mbolar |
last post by:
operator = (const char *string) {
if(m_string) {
free(m_string);
m_string = 0;
}
if(string) {
m_string = strdup(string);
}
}
|
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
|
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
|
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:
| |
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_
|
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:
|
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;
|
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 ` ...
|
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,...
|
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...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |