编译文件时出现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 )
表示在&
令牌之前存在期望的)
。这对我来说没有任何意义,因为没有打开的(
。我只是不知道为什么会出现这个错误。Printer
和NameServer
只是单独的类,是项目的一部分,但。。我是否也需要包括它们的头文件?
非常感谢您的帮助!
您需要包含正在使用的任何类的头文件,甚至是同一项目中的类。编译器将每个单独的源文件作为一个单独的翻译单元进行处理,如果定义类的头没有包含在该翻译单元中,它就不会知道类是否存在。
您的.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
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 错误:未在此范围内声明'reverse'