C structure as a data type -
i want able this:
typedef struct { char* c_str; } string; string s = "hello";
is possible in way?
i know possible this:
typedef struct { char* c_str; } string; string s = { "hello" };
but not curly brackets when 1 member variable.
you use typedef
instead of struct
:
typedef char* string; string s = "hello";
but const string
make pointer const, , not pointed-to data. const string s
equivalent char* const s
. solution may define additional type const strings:
typedef char* string; typedef const char* const_string;
for original struct, same true. (c++ has same "problem", why has iterator
, const_iterator
in container types.)
an advantage of typedef pointer type can type
string s1, s2, s3;
instead of
char *s1, *s2, *s3;
Comments
Post a Comment