我在使用 C++ 语言和 IloCplex 框架时遇到编译问题。
我首先尝试使用 makefile 编译整个项目,但出现意外错误,类头调用 AbstractModel,以确保此错误不是由其他文件引起的,我决定只用这个命令编译这个类:
g++ -o AbstractModel.o -c -I/path/to/cplex/include -I/path/to/concert/include -DIL_STD AbstractModel.cpp
然后我意识到我收到了相同的错误消息,这是 AbstractModel 类:
和 type.h 类:
错误如下:
In file included from AbstractModel.hpp:12, from AbstractModel.cpp:7: type.h:6: error: expected constructor, destructor, or type conversion before ‘typedef’ In file included from AbstractModel.cpp:7: AbstractModel.hpp:50: error: ‘Vector’ does not name a type AbstractModel.hpp:51: error: ‘Vector’ does not name a type
有什么建议吗?
P.S:Cplex 在这台计算机上运行良好,我有另一个项目具有相同类型的类,可以使用相同的命令完美编译。
最佳答案
CustomType.hpp 必须在 AbstractModel.hpp 之前#included,因为 CustomType.hpp 定义了 AbstractModel.hpp 使用的类型定义。
从您粘贴的内容中无法看出是否确实如此。
理想情况下,您的 AbstractModel.hpp header 将 #include "CustomType.hpp"
本身,而不是依赖它的完成。
关于c++ - 错误 : "expected constructor, destructor, or type conversion before ' typedef' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9293884/