Reputation: 1367
I have a class called BottlingPlant. I created the following headerfile:
#ifndef __BOTTLINGPLANT_H__
#define __BOTTLINGPLANT_H__
#include <iostream>
class BottlingPlant {
public:
BottlingPlant( Printer &prt, NameServer &nameServer, unsigned int numVendingMachines, unsigned int maxShippedPerFlavour, unsigned int maxStockPerFlavour, unsigned int timeBetweenShipments );
void getShipment( unsigned int cargo[ ] );
void action();
};
#endif
And the following .cc file:
#include <iostream>
#include "PRNG.h"
#include "bottlingplant.h"
BottlingPlant::BottlingPlant( Printer &prt, NameServer &nameServer, unsigned int numVendingMachines, unsigned int maxShippedPerFlavour, unsigned int maxStockPerFlavour, unsigned int timeBetweenShipments ) {
}
void BottlingPlant::getShipment( unsigned int cargo[ ] ) {
}
void BottlingPlant::action() {
}
When I try compiling the .cc, it gives me an error in the .cc and .h at the line:
BottlingPlant::BottlingPlant( Printer &prt, NameServer &nameServer, unsigned int numVendingMachines, unsigned int maxShippedPerFlavour, unsigned int maxStockPerFlavour, unsigned int timeBetweenShipments )
Saying that there is an expected )
before the &
token. This doesn't make any sense to me as there is no open (
. I'm just not sure why it's giving this error. Printer
and NameServer
are just separate classes a part of the project but.. do I need to include their header files as well or no?
Any help is greatly appreciated!
Upvotes: 0
Views: 91
Reputation: 49473
Your .h file should include the headers which have the class definitions for Printer and NameServer. As an example if they're in MyHeader.h, the following example shown should fix those errors.
#ifndef __BOTTLINGPLANT_H__
#define __BOTTLINGPLANT_H__
#include <iostream>
#include "MyHeader.h"
class BottlingPlant {
public:
BottlingPlant( Printer &prt, NameServer &nameServer, unsigned int numVendingMachines, unsigned int maxShippedPerFlavour, unsigned int maxStockPerFlavour, unsigned int timeBetweenShipments );
void getShipment( unsigned int cargo[ ] );
void action();
};
#endif
Upvotes: 1
Reputation: 34563
You need to include the header files for any classes you're using, even classes in the same project. The compiler processes each individual source file as a separate translation unit, and it won't know that a class exists if the header that defines it hasn't been included in that translation unit.
Upvotes: 5