The entire contents of my Peer.h and Overseer.h are as follows:
/***** Peer.h *****/
#ifndef _Peer_h_
#define _Peer_h_
#include "Communications.h"
class Peer {
private:
int peerID;
string peerIP;
int peerPort;
public:
int getPeerID() {
return peerID;
}
string getPeerIP() {
return peerIP;
}
int getPeerPort() {
return peerPort;
}
void setPeerID( int ID ) {
peerID = ID;
}
void setPeerIP( string IP ) {
peerIP = IP;
}
void setPeerPort( int port ) {
peerPort = port;
}
};
#endif
/****** Overseer.h ********/
#ifndef _Overseer_h_
#define _Overseer_h_
#include "Peer.h"
#include <vector>
class Overseer {
private:
vector<Peer> connectedPeers;
public:
vector<Peer> getConnectedPeers() {
return connectedPeers;
}
};
#endif
Once again, the error message is:
g++ -g -c -o Overseer.o Overseer.cc
g++ -g -c -o Communications.o
Communications.cc
g++ Overseer.o Util.o Communications.o Parser.o -o
overseer -lsocket -lnsl
g++ -g -c -o Peer.o Peer.cc
In file included from Communications.h:19,
from Peer.h:4,
from Peer.cc:1:
Overseer.h:9: error: `Peer' was not declared in this scope
Overseer.h:9: error: template argument 1 is invalid
Overseer.h:9: error: template argument 2 is invalid
Overseer.h:9: error: ISO C++ forbids declaration of `connectedPeers' with
no
type
Overseer.h:12: error: `Peer' was not declared in this scope
Overseer.h:12: error: template argument 1 is invalid
Overseer.h:12: error: template argument 2 is invalid
Overseer.h:12: error: ISO C++ forbids declaration of `getConnectedPeers'
with
no type
make: *** [Peer.o] Error 1
Any suggestion to the cause of the error and a fix is greatly
appreciated.
On Mon, 21 Mar 2005, David White wrote:
"William" <wh******@student.cs.uwaterloo.ca> wrote in message
news:Pi******************************@cpu02.studen t.cs.uwaterloo.ca... In Peer.h, I have:
class Peer {
// ...
};
In Overseer.h, I have:
#include "Peer.h"
#include <vector>
using namespace std;
It's a bad idea to put this in a header file. It means that every file that
includes this header is forced to have all names in std:: visible at global
scope, and all it does here is save you a couple of "std:::" on your
vectors. Put it in files that aren't #included by other files if you like,
but not here.
class Overseer {
private:
vector<Peer> connectedPeers;
public:
vector<Peer> getConnectedPeers() {
return connectedPeers;
}
};
I got the following error when I attempted to compile my code:
In file included from Communications.h:19,
from Peer.h:4,
from Peer.cc:1:
Overseer.h:11: error: `Peer' was not declared in this scope
Overseer.h:11: error: template argument 1 is invalid
Overseer.h:11: error: template argument 2 is invalid
Overseer.h:11: error: ISO C++ forbids declaration of `connectedPeers' with
no
type
Overseer.h:14: error: `Peer' was not declared in this scope
Overseer.h:14: error: template argument 1 is invalid
Overseer.h:14: error: template argument 2 is invalid
Overseer.h:14: error: ISO C++ forbids declaration of `getConnectedPeers'
with
no type
make: *** [Peer.o] Error 1
In Overseer.h, it is very clear that I have #include "Peer.h".
1) What is the cause of the error?
2) Any suggestions for a fix is appreciated.
I can't explain the errors. It compiled by VC++ 6.0 with no errors for me. I
suspect that you haven't posted the entire contents of the header files and
inadvertently removed the cause of your errors.
DW