The following compiles fine (on g++ 8.3.0-6 and --std=c++17) with the std::stringstream being a non-static class member:
#include <iostream>
#include <sstream>
class Foo {
public:
std::stringstream ss;
};
int main() {
Foo f;
f.ss << "bar\n";
std::cout << f.ss.str();
}
But the following doesn't (same compiler, same options), where the stringstream is static inline:
#include <iostream>
#include <sstream>
class Foo {
public:
static inline std::stringstream ss;
};
int main() {
Foo::ss << "bar\n";
std::cout << Foo::ss.str();
}
My compiler tells me that std::stringstream has no default constructor, which it actually should:
error: no matching function for call to ‘std::__cxx11::basic_stringstream<char>::basic_stringstream()’
static inline std::stringstream ss;
^~
What am I doing wrong here?