K
Kevin Frey
I am porting Managed C++ code from VS2003 to VS2005. Therefore adopting the
new C++/CLI syntax rather than /clrldSyntax.
Much of our managed code is concerned with interfacing to native C++ code
(ie. wrappers etc). In Managed C++ there was an automatic conversion between
const char* and String^. This was useful to us for two reasons:
1. We declared our string constants as eg. const char* const c_My_Constant =
"blah", and these strings could be easily utilised (ie. assigned) to either
a std::string or a String^.
2. We could easily convert/assign std::string to String^ using the .c_str( )
method.
Both of these techniques no longer work in C++/CLI. The implicit conversion
has now disappeared.
Now, in case (2) I have no problem changing all this code to instead use a
"to_string( )" kind of method that converts std::string to String^. It
probably even has the benefit of making the code more readable.
I could obviously do the same thing for case (1) but it irks me to have to
convert a "constant". Unfortunately, however, I have numerous situations
where the same constant will be used by both native and managed C++.
Is there a better way to achieve this?
Thanks
Kevin
new C++/CLI syntax rather than /clrldSyntax.
Much of our managed code is concerned with interfacing to native C++ code
(ie. wrappers etc). In Managed C++ there was an automatic conversion between
const char* and String^. This was useful to us for two reasons:
1. We declared our string constants as eg. const char* const c_My_Constant =
"blah", and these strings could be easily utilised (ie. assigned) to either
a std::string or a String^.
2. We could easily convert/assign std::string to String^ using the .c_str( )
method.
Both of these techniques no longer work in C++/CLI. The implicit conversion
has now disappeared.
Now, in case (2) I have no problem changing all this code to instead use a
"to_string( )" kind of method that converts std::string to String^. It
probably even has the benefit of making the code more readable.
I could obviously do the same thing for case (1) but it irks me to have to
convert a "constant". Unfortunately, however, I have numerous situations
where the same constant will be used by both native and managed C++.
Is there a better way to achieve this?
Thanks
Kevin