簡體   English   中英

編譯文件時出現C ++錯誤

[英]C++ error when compiling file

我有一個叫做BottlingPlant的類。 我創建了以下頭文件:

#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

以及以下.cc文件:

#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() {

}

當我嘗試編譯.cc時,它在行處的.cc和.h中給我一個錯誤:

BottlingPlant::BottlingPlant( Printer &prt, NameServer &nameServer, unsigned int numVendingMachines, unsigned int maxShippedPerFlavour, unsigned int maxStockPerFlavour, unsigned int timeBetweenShipments )

說在&令牌之前有一個預期的) 這沒有任何意義,我因為沒有開放( ,我只是不知道為什么它給這個錯誤。 PrinterNameServer只是單獨的類項目的一部分,但...我需要包括它們的頭文件,還是沒有?

任何幫助是極大的贊賞!

您需要包括所用任何類的頭文件,甚至是同一項目中的類。 編譯器將每個單獨的源文件作為一個單獨的翻譯單元進行處理 ,如果定義該文件的標頭未包含在該翻譯單元中,則它將不知道存在一個類。

您的.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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM