c++ - Forward declaration of std::wstring -
// header file. class myclass; // can forward declared because function uses reference. // however, how can forward declaraion std::wstring? // class std::wstring; doesn't work. void boo(const myclass& c); void foo(const std::wstring& s);
you can't. #include <string>
, have (almost) no choice.
the reason wstring
defined in namespace std
, typedef'd std::basic_string<wchar_t>
. more elaborately, std::wstring
std::basic_string<wchar_t, std::char_traits<wchar_t> >
. means in order forward-declare std::wstring
you'd have forward-declare std::char_traits<>
, std::basic_string<>
inside namespace std
. because (apart few exceptions) standard forbids adding definitions or declarations namespace std
(17.4.3.1/1) can't forward-declare standard template or type in standard-conforming way. specifically, means can't forward-declare std::wstring
.
and yes, agree convenient have <stringfwd>
header, <iosfwd>
<iostream>
. there isn't. <string>
not hardcore compile <iostream>
, nevertheless. have 2 choices: #include<string>
or use opaque pointer.
Comments
Post a Comment