__boxing helena - i mean parity...

P

Peter Oliphant

OK, I'm mixing old style with new style, so sue me... : )

Will under old syntax, I'm able to create a SerialPort instance. But, when I
try to convert the Parity proerty to a String*, I get the following compiler
error:

error C3610: value type must be 'boxed'

Here is the code:

SerialPort* port = new SerialPort() ;
Parity parity = port->Parity() ;
String* port_str = parity.ToString() ; // 'boxing' error

Never 'boxed' before, don't know how. How do I convert Parity to a String*
equivalent (i.e., how do I change the above code to properly box 'parity' so
ToString() can be evaluated)? If I write the equivalent code in /clr format
no boxing is necessary ('natch), but I need to do this (for now) in old
syntax.

Thanks in advance for responses! : )

[==P==]

PS - I'm writnig a home project using the new /clr syntax. If you START
using this syntax its awesome! If you have to convert old syntax managed C++
to it, its an intimidating task to say the least... : )
 
T

Tomas Restrepo \(MVP\)

Peter,
OK, I'm mixing old style with new style, so sue me... : )

Will under old syntax, I'm able to create a SerialPort instance. But, when
I try to convert the Parity proerty to a String*, I get the following
compiler error:

error C3610: value type must be 'boxed'

Here is the code:

SerialPort* port = new SerialPort() ;
Parity parity = port->Parity() ;
String* port_str = parity.ToString() ; // 'boxing' error

Never 'boxed' before, don't know how. How do I convert Parity to a String*
equivalent (i.e., how do I change the above code to properly box 'parity'
so ToString() can be evaluated)? If I write the equivalent code in /clr
format no boxing is necessary ('natch), but I need to do this (for now) in
old syntax.

You need to box the value here because in old style MC++, you couldn't
directly access inherited methods in a value (i.e. an instance of a value
type) unless the type overrode those methods (that's why you can call
ToString() directly on some value types and not on others).

In this case, you need to box it, which can be done using the __box()
operator:

String* port_str = __box(parity)->ToString() ;
 
P

Peter Oliphant

Yup, that did the trick! Thanks! : )

[==P==]

Tomas Restrepo (MVP) said:
Peter,


You need to box the value here because in old style MC++, you couldn't
directly access inherited methods in a value (i.e. an instance of a value
type) unless the type overrode those methods (that's why you can call
ToString() directly on some value types and not on others).

In this case, you need to box it, which can be done using the __box()
operator:

String* port_str = __box(parity)->ToString() ;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top