A
alf.p.steinbach
one other error
Well you haven't got to a FIRST error yet.
But you think that you have.
This group used to be frequented by the language creator (Bjarne), by the committee secretaries who penned the standard (first Andrew, then Pete), andby lots of committee members, compiler writers (including Greg Comeau and Daveed) and so on.
About the only authoritative people I see here now are some old-time clc++-ers like Ian Collins and "Tib" (I can never recall the name!), plus us old clc++m moderators (James, Victor and myself). That is, to the degree that having participated for a long time on Usenet confers any authority (except that James is also a committee member, I think). So it's gone downhill withthe influx of novices and trolls, called "November" in Usenet jargon.
This means that you would do well by generally IGNORING or at least CHECKING statements here that are not rooted in simple verifiable fact, or clear logic.
there is no need of this ungly word "const"
In the C++11 standard the easiest way to confirm that it indeed is needed is the Annex C (about C compatibility) discussion of §2.14.5 (string literals), which includes this example:
char* p = "abc"; // valid in C, invalid in C++
But if someone coughs that up as a reference, then don't just blindly believe it. For EXAMPLES in the standard are not "normative", which means that they can be wrong. Indeed, a whole bunch of examples in C++98 were incorrect(it's mostly corrected now in C++11).
The standardeese that that now forbids that implicit conversion is difficult to find, because it was done by simply REMOVING the C++03 text that allowed it,
C++03 §4.2/2
"A string literal (2.13.4) that is not a wide string literal can be
converted to an rvalue of type “pointer to char”;"
I.e., it's a case of finding the absence of text ;-); in C++11 there is no such.
Here's an example:
Code:
#include <iostream>
using namespace std;
// Intentionally does not compile with CONFORMING compiler:
void say( char* s )
{
cout << s << endl;
}
auto main() -> int
{
say( "Uh oh..." );
}
Compiling with a MinGW Windows variant of g++ (the GNU C++ compiler) in C++11-confoming mode -- I'm not quite sure what options I've used, because it's all in the configuration:
[example]
[D:\dev\test]
foo.cpp: In function 'int main()':g++ foo.cpp
foo.cpp:12:21: error: deprecated conversion from string constant to 'char*'[-Werror=write-strings]
cc1plus.exe: some warnings being treated as errors
[D:\dev\test]
[/example]
Cheers & hth.,
- Alf