为什么GCC不允许我创建"内联静态std::stringstream"?
Why GCC doesn't allow me to create `inline static std::stringstream`?
我会直接去MCVE:
#include <sstream>
struct A
{
inline static std::stringstream ss;
};
GCC 7.2和7.1拒绝以以下错误进行编译:
错误:呼叫'std :: __ cxx11 :: basic_stringstream :: basic_stringstream()' 内联静态std :: stringstream ss; ^〜在Blah的文件中包括:1:0:[with _chart = char;_traits = std :: char_traits;_Alloc = STD ::分配器] BASIC_STRINGSTREAM(BASIC_STRINGSTREAM && __RHS) ^~~~~~~~~~~~~~~~~/Opt/compiler-explorer/GCC-7.2.0/include/c /7.2.0/sstream:723:7:注意:候选人期望1个参数,0提供
您可以在没有任何标志的情况下重现,以及-std=c++17
。
clang 5.0毫无问题地编译它。
其他类(例如std::string
)可以毫无问题地制作inline static
。
使其非内线静态删除错误。
不是GCC错误还是我缺少某些东西?
错误。减少到:
struct C { explicit C() {} };
struct A {
inline static C c;
};
GCC初始化处理代码中某个地方的某个地方错误地将其视为副本定位上下文,该上下文忽略了明确的默认构造函数。
相关文章:
- 静态 std::map instatiation 在类的方法中调用构造函数吗?
- 静态 std::stringstream 的叮当整警告
- 静态std::unordereded_map的默认值
- 使用静态 std::vector 类成员时出现访问冲突
- 从内部使用静态 std::string 的函数返回 const char * 是否安全?
- 具有静态 std::array 的神经网络比使用动态 C 数组的神经网络慢
- 分配大型静态 std::unordered_map 会导致堆栈溢出
- 初始化常量静态 std::map unique_ptr作为值
- 为什么GCC不允许我创建"内联静态std::stringstream"?
- 使用局部静态std :: ARNE_FLAG和局部静态指针对静态变量的线程安全初始化
- 初始化静态std :: multimap在其中声明的方法
- 如何使用静态函数填充静态 std::map
- g++:编译一个巨大的静态std::vector
- 初始化静态 std::map<int, unique_ptr<int>> in C++
- 如何初始化类型特征的静态 std::unordered_map
- 将 v8::Local<v8::Object> 存储在类中 静态 std::vector
- 当我返回其引用时,如果超出范围,则静态std::vector将取消
- 使用访问器访问静态std::集,这是明智的,还是我应该直接访问它
- 来自文字的静态std::string对象的宏
- 一个尝试非确定性有限状态机(c++),是静态std::map的好主意