C++ Inheritance Problems

Soldato
Joined
7 Apr 2004
Posts
4,212
Hi,

Im trying to get some basic C++ inheritance working across 2 header files, and its been a while since ive used C++, so its probably something really silly :(

Header 1: serv.h
Code:
#include <iostream>
#include <vector>

using namespace std;

struct server_data
{
	string server_name;	
	string host_name;	
	int port;	
	string user_name;	
	string password;	
	bool require_authentication;
	int max_connections; 

	int priority;

	bool operator < (const server_data& a) const
	{
		return priority < a.priority;
	}
};

class NCServer
{

	public:
		vector<server_data> nc_server;
		int AddServer(server_data sc);
		int RemoveServer(string server_name);

};

Header 2: conn.h
Code:
#include "serv.h"

class NCConnection : public NCServer
{
public:


};

I get a whole host of redefinition errors for things in the first header file :confused:

Any ideas what I have missed out / doing wrong?

Thanks

Jack
 
Thanks a lot Mr Jack, the missing header guards fixed the problem.

Also, you mentioned that i shouldn't include namespace std in headers, well as you can see in the header above i have a struct that uses std::string? Is there anyway i can just declare a struct in the header and then implement it in the .cpp? Or is what i have done correct?
 
Back
Top Bottom