代码在 CLion 中编译,但在命令提示符中不编译
Code compiles in CLion but not in Command Prompt
我正在尝试使用 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++ 库并且需要(想要)使用嵌套名称空间以提高代码的可读性。但是,当我尝试使用 g++ main.c
.
下面的代码是我将拥有的示例——一个嵌套的命名空间,然后是一些函数或 类:
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
}
^
我想知道我做错了什么以及如何解决这个问题。
谢谢!