这是在编译时返回的异常错误,仅限于一些编译器参数.
好的 g++ -std=c++11 -m64 -O3 -DNDEBUG
但是g++ -std=c++11 -m64 -Wall -g,出现此问题:
宏"htonl"传递了7个参数,但只占用了1个
码:
const unsigned int h = htonl(hash::CompileTime<'A', 'S', 't', 'r', 'i', 'n', 'g'>::hash);
Run Code Online (Sandbox Code Playgroud)
我不确定问题是来自调用htonl还是来自我的模板化的哈希.
你知道怎么解决这个问题吗?
其他信息:
template<const char C0, const char C1 = '\0', const char C2 = '\0',
const char C3 = '\0', const char C4 = '\0', const char C5 = '\0',
const char C6 = '\0', const char C7 = '\0', const char C8 = '\0',
const char C9 = …Run Code Online (Sandbox Code Playgroud) 环境:
这是代码:
#include <numeric>
...
auto g = std::gcd(10, 4);
...
Run Code Online (Sandbox Code Playgroud)
我已经打开-std=c++17了编译命令中的选项:
g++ -m64 -std=c++17 -c -g -w -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp
Run Code Online (Sandbox Code Playgroud)
然后我得到了错误:
错误:“ gcd”不是“ std”的成员
从此网页开始,std::gcd自C ++ 17开始引入。
在此网页上,我的g ++版本支持C ++ 17。
但是为什么仍然存在错误?相同的代码可以在Visual Studio 2017中编译而不会出现任何错误。
下面是用于重现该错误的最少代码。
#include <iostream>
#include <mutex>
#include <vector>
class A {
std::mutex mutex;
public:
A(){};
};
int main()
{
std::vector<std::pair<std::string,A>> aa;
A a;
//aa.push_back(std::make_pair(std::string("aa"),A()));
//aa.push_back(std::make_pair(std::string("aa"),a));
aa.push_back(std::make_pair(std::string("aa"),std::move(a)));
}
Run Code Online (Sandbox Code Playgroud)
以下是错误。
用于x64的Microsoft(R)C / C ++优化编译器版本19.16.27026.1版权所有(C)Microsoft Corporation。版权所有。
> C:\Program Files (x86)\Microsoft Visual
> Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\xlocale(319):
> warning C4530: C++ exception handler used, but unwind semantics are
> not enabled. Specify /EHsc C:\Program Files (x86)\Microsoft Visual
> Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\utility(405):
> error C2440: '<function-style-cast>': cannot convert from 'initializer
> list' to '_Mypair' C:\Program Files (x86)\Microsoft Visual
> Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\utility(405):
> …Run Code Online (Sandbox Code Playgroud) 为什么以下代码片段输出3?
// Example program
#include <iostream>
#include <string>
int main()
{
std::cout << + '+' - '-' * '*' / '/' << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
GCC输出在这里. Clang的输出也相同.