0

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!

4

2 に答える 2

5

同じプロジェクト内のクラスであっても、使用しているすべてのクラスのヘッダー ファイルを含める必要があります。コンパイラは個々のソース ファイルを個別の翻訳単位として処理し、クラスを定義するヘッダーがその翻訳単位に含まれていない場合、クラスが存在することを認識しません。

于 2012-07-19T01:08:21.917 に答える
1

.h ファイルには、Printer と NameServer のクラス定義を持つヘッダーが含まれている必要があります。例として、それらが MyHeader.h にある場合、次の例でこれらのエラーを修正する必要があります。

#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
于 2012-07-19T01:12:54.157 に答える