ListViewItem constructior question ?

HI again, getting my money's worth this week.....

Does anyone know why (and they way around) the fact that the ListViewItem class constructor accepts this just fine:

ListViewItem( "item1",0 );

But doesn't like this:

ListViewItem( AStringObject.c_str() ,0 );

Or any other variation or casting to (char *).

Evidently "item1" adheres to some Serialization type that it likes?

A real pain, because how often to we know the literals in advance that we want to display?
Last edited on
1. "item1" is probably char* that is a pointer to non constant char
2. AStringObject.c_str() returns char const * that is a pointer to constant char

Compiler won't implicitly convert a char const * to char * - you
will have to do it explicitly - that is to say cast it
That's a good point. Does this work?

1
2
char str[] = "item1";
ListViewItem ( str, 0 );

HI again - in the interest of closing the loop...sorry...occupational hazard....

This seems to be what the ListViewItem CTOR wanted:

ListViewItem^ lvi_p = gcnew ListViewItem(managed_name);

And 'managed_name' in turn was a: "String ^"

String ^ managed_name = gcnew System::String((*ri)->GetName().c_str());

Evidently this is C++/CLI's "managed" type; that classes like ListViewItem insist on receiving.

oooh goody. More new stuff ;) thanks guys.
Topic archived. No new replies allowed.