我正在尝试使用C ++库,并且需要(想要)使用嵌套的名称空间,以提高代码的可读性。但是,尝试使用g++ main.c
在Windows命令提示符下编译我的代码时遇到了问题。
下面的代码是我将拥有的一个示例-嵌套的名称空间,然后是一些函数或类:
namespace gpc::warning { void raiseError() { std::cout << "Error...\n"; exit(1); } }
下面的代码是我的
main.c
文件的示例:
#include <iostream> #include "Warning/raise.hpp" int main() { std::cout << "Hello, World!" << std::endl; gpc::warning::raiseError(); return 0; }
[当我在CLion中运行此简单程序时,它可以编译并完美运行,但是,当我在Windows 10命令提示符中运行代码时,出现以下错误,告诉我有关名称空间的一些信息:
In file included from main.cpp:2:0: Warning/raise.hpp:10:14: error: expected '{' before '::' token namespace gpc::warning { ^ Warning/raise.hpp:10:16: error: 'warning' in namespace '::' does not name a type namespace gpc::warning { ^ main.cpp: In function 'int gpc::main()': main.cpp:9:10: error: 'gpc::warning' has not been declared gpc::warning::raiseError(); ^ main.cpp: At global scope: main.cpp:12:1: error: expected '}' at end of input } ^
我想知道我做错了什么以及如何解决此问题。
谢谢!
我正在尝试使用C ++库,并且需要(想要)使用嵌套的名称空间,以提高代码的可读性。但是,尝试在Windows中编译我的代码时遇到问题...
尝试将您的g++
版本更新为6.1.0
或更高版本。