chinmay.sahoo
New member
The type of a string literal, such as "Pooh", is treated differently within C++/CLI; it is more nearly a kind of System::String than a C-style character string pointer. This has a visible impact with regard to the resolution of overload functions. For example:
In ISO-C++, this resolves to instance (3)—a string literal is more nearly a kind of constant pointer to character than it is an ISO-C++ standard library string type. Under C++/CLI, however, this call resolves to (1)—a string literal is now more nearly a kind of System::String than pointer to character. The type of a string literal is treated differently within C++/CLI. It has been designed to be more nearly a kind of System::String than a C-style character string pointer.
public ref class R {
public:
void foo( System::String^ ); // (1)
void foo( std::string ); // (2)
void foo( const char* ); // (3)
};
void bar( R^ r )
{
// which one?
r->foo( "Pooh" );
}
In ISO-C++, this resolves to instance (3)—a string literal is more nearly a kind of constant pointer to character than it is an ISO-C++ standard library string type. Under C++/CLI, however, this call resolves to (1)—a string literal is now more nearly a kind of System::String than pointer to character. The type of a string literal is treated differently within C++/CLI. It has been designed to be more nearly a kind of System::String than a C-style character string pointer.
void foo( System::String^ ); // (1)
void foo( std::string ); // (2)
void foo( const char* ); // (3)
void bar( R^ r ){ r->foo( "Pooh" ); } // which foo?
ISO-C++: // (3) is invoked ...
C++/CLI: // (1) is invoked ...