c++ - 错误 : "expected constructor, destructor, or type conversion before ' typedef' "

标签 c++ compilation cplex

我在使用 C++ 语言和 IloCplex 框架时遇到编译问题。

我首先尝试使用 makefile 编译整个项目,但出现意外错误,类头调用 AbstractModel,以确保此错误不是由其他文件引起的,我决定只用这个命令编译这个类:

g++ -o AbstractModel.o -c -I/path/to/cplex/include -I/path/to/concert/include -DIL_STD AbstractModel.cpp

然后我意识到我收到了相同的错误消息,这是 AbstractModel 类:

http://pastebin.com/B9YiqKUS

和 type.h 类:

http://pastebin.com/trQ6BDBK

错误如下:

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/

相关文章:

c++ - 最终链接失败 : Invalid argument when including windows. h

regex - 多行的 Emacs 编译模式正则表达式

python-3.x - 在python中为cplex求解器pyomo设置optimalitytarget参数

python - CPLEX 二次 objective-c PLEX 错误 1017 : Not available for mixed-integer problems

c++ - 有关 C++ 中的 SNMP 的帮助吗?

c++ - 将文本文件读取为字符串的最短方法

c - 对 xxx include 的 undefined reference 不起作用

java - 更改 VSCode 中的 java 构建位置(代码运行程序)

scheduling - 如何在 CPLEX 的调度问题中添加新的约束?

c++ - OpenGL/C++ 和 Maya 集成