c – constexpr lambda ’x’没有命名类型;你的意思是’x’?

c – constexpr lambda ’x’没有命名类型;你的意思是’x’?,第1张

概述我正在尝试使用C 17的constexpr lambdas来获取编译时字符串: #include <utility>template <char...>struct str{ constexpr auto operator==(const str&) const { return true; } void foo() const;};template <typename S, 我正在尝试使用C 17的constexpr lambdas来获取编译时字符串:

#include <utility>template <char...>struct str{  constexpr auto operator==(const str&) const { return true; }  voID foo() const;};template <typename S,std::size_t... Ns>constexpr auto make_str(S s,std::index_sequence<Ns...>){  return str<s()[Ns]...>{};}#define liT(s) \  make_str([]() { return s; },std::make_index_sequence<sizeof(s) - 1>{})constexpr auto x = liT("hansi");constexpr auto y = x;static_assert(x == y);

到目前为止看起来不错但后来我试着调用一个成员函数:

x.foo();

使用来自trunk(g(GCC)7.0.0 20161102)的当前gcc,我收到以下错误消息:

c.cpp:19:1: error: ‘x’ does not name a type; dID you mean ‘x’? x.foo();

有关演示,请参见https://godbolt.org/g/uN25e1

由于我甚至没有尝试使用x作为一种类型,这让我觉得奇怪.

这是编译器错误吗?还是x真的很奇怪?

解决方法 正如其他人的评论所指出的,这只是调用函数命名空间范围的结果.

恕我直言,错误信息是相当模糊的.

总结

以上是内存溢出为你收集整理的c – constexpr lambda /’x’没有命名类型;你的意思是’x’?全部内容,希望文章能够帮你解决c – constexpr lambda /’x’没有命名类型;你的意思是’x’?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1224985.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存