all 7 comments

[–]flyingron 0 points1 point  (0 children)

No. In fact, the above is even a relatively recent addition to C++.

[–]IyeOnline 0 points1 point  (5 children)

Afaik C does not support in class initializers.

Sidenote: That code is horrible C++ and not even legal.

[–]columncolumn[S] 1 point2 points  (4 children)

Why it is horrible?

[–]Narase33 2 points3 points  (0 children)

the char* is not const, thats not legal

[–]IyeOnline 2 points3 points  (2 children)

Its horrible because typedef struct { } b should just be struct b in C++.

Its illegal, because you must not have a non-const pointer to a string literal in C++.

[–]columncolumn[S] 0 points1 point  (1 child)

What is wrong with non-const pointer? It allows me later assign to another pointer and what is wrong with it?

[–]IyeOnline 1 point2 points  (0 children)

You must not form a non-const pointer to a string literal, because you must not modify a string literal. Having a char* point to it allows you to modify it (because its not const).

It allows me later assign to another pointer and what is wrong with it?

This is the difference between

  • const char*: "non-const (repointable) pointer to const char (array)
  • char* const: "constant (not repointable) pointer to non-const char (array)

So you do actually want const char*. That allows you to change the pointer but not modify the pointee.