I am trying to build a C++/CLR form app
And in the code below
I am trying to get the length of the string of GetTb
Which is a string retrieved from a textbox Tb_Return
Tb_Return->Text = "This is a test String";
String^ GetTb = Tb_Return->Text;
int len = GetTb.Length();
Tb_Return->Text = GetTb;
In Line 3, Visual Studio keeps highlighting the GetTb
variable with the error below
expression must have class type but it has type
And when I try to change the .
into ->
, the error message changes to below
expression preceding parentheses of apparent call must have have (pointer-to-) function type
How can I fix these errors?
There are 2 issues here:
GetTb
is a handle to an object in c++/cli.->
operator (or *
with .
similarly to c++ pointers).System::String::Length
is a property.()
).Therefore the correct way to access the Length
property of GetTb
is:
int len = GetTb->Length;