Re: Which constructor?
Victor Bazarov <v.bazarov@comcast.invalid> writes:
::std::string t ={ "beta" }; }
This is a copy-initialization, preceded by the same parameterized one in
order to construct a temporary, I think. The compiler is still allowed
to forgo creation of the temporary, but the copy c-tor has to exist and
be accessible.
Are you seeing any problem constructing an std::string?
I am writing about this in my German-language C++ tutorial,
and wanted to be sure that I explain it correctly. I would
have guessed that it was copy initialization, but I wanted
to be sure.
The best thing to be sure would be a source of
::std::string, and then insert debug print statements into it.
In fact, there is a GNU header:
namespace __gnu_debug
{
/// Class std::basic_string with safety/checking/debug instrumentation.
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT> >
class basic_string
...
which has constructors:
basic_string(const _CharT* __s, size_type __n,
const _Allocator& __a = _Allocator())
: _Base(__gnu_debug::__check_string(__s, __n), __n, __a)
{ }
and I tought I could just insert
::std::cerr << "this was just called\n";
into the braces. But the compiler complains
debug\string [Error] 'cerr' in namespace 'std' does not name a type
even after including ostream and iostream in this header and
trying dozen of other approaches.