S
Steve Richter
here is a warning I am getting in a C++ .NET compile:
c:\SrNet\jury\JuryTest.cpp(55) : warning C4927: illegal conversion;
more than one user-defined conversion has been implicitly applied
while calling the constructor 'MyString::MyString(const
wchar_t *)'
c:\SrNet\jury\JuryTest.h(21) : see declaration of
'MyString::MyString'
The class "StringData" uses a, whatever you call it, operator const
whar_t*( ) to represent itself to other classes as a "const whar_t*".
A 2nd class, "MyString" has a constructor that accepts a "const
wchar_t*" when it is instantiated. Its a marriage made in code
heaven.
The classes are below, here is a function that produces the warning.
MyString TestFunc2( )
{
StringData data ;
MyString sData ;
sData = L"abc" ;
data = sData ; // no warnings when
sData = data ; // assigning either way.
return data ; // get the c4927 warning here. wtf?
}
I dont understand the warning. Esp the wording "illegal conversion".
I thought that C++ is all about how a class can be
assigned/converted/casted into another class?
Great NG,
Steve Richter
// ------------------------ MyString -------------------------------
class MyString : public std::basic_string<wchar_t>
{
private:
public:
MyString& operator=( const wchar_t* sVlu )
{ assign( sVlu ) ; return *this ; }
operator const wchar_t*( ) const
{ return c_str( ) ; }
public:
MyString( )
{ }
MyString( const wchar_t* sVlu )
{ assign( sVlu ) ; }
} ;
// ---------------------- StringData ----------------
class StringData
{
private:
std::basic_string<wchar_t> msVlu ;
public:
StringData& operator=( const wchar_t* sData )
{ msVlu = sData ; return *this ; }
operator const wchar_t*( ) const
{ return msVlu.c_str( ) ; }
public:
StringData( )
{ }
} ;
c:\SrNet\jury\JuryTest.cpp(55) : warning C4927: illegal conversion;
more than one user-defined conversion has been implicitly applied
while calling the constructor 'MyString::MyString(const
wchar_t *)'
c:\SrNet\jury\JuryTest.h(21) : see declaration of
'MyString::MyString'
The class "StringData" uses a, whatever you call it, operator const
whar_t*( ) to represent itself to other classes as a "const whar_t*".
A 2nd class, "MyString" has a constructor that accepts a "const
wchar_t*" when it is instantiated. Its a marriage made in code
heaven.
The classes are below, here is a function that produces the warning.
MyString TestFunc2( )
{
StringData data ;
MyString sData ;
sData = L"abc" ;
data = sData ; // no warnings when
sData = data ; // assigning either way.
return data ; // get the c4927 warning here. wtf?
}
I dont understand the warning. Esp the wording "illegal conversion".
I thought that C++ is all about how a class can be
assigned/converted/casted into another class?
Great NG,
Steve Richter
// ------------------------ MyString -------------------------------
class MyString : public std::basic_string<wchar_t>
{
private:
public:
MyString& operator=( const wchar_t* sVlu )
{ assign( sVlu ) ; return *this ; }
operator const wchar_t*( ) const
{ return c_str( ) ; }
public:
MyString( )
{ }
MyString( const wchar_t* sVlu )
{ assign( sVlu ) ; }
} ;
// ---------------------- StringData ----------------
class StringData
{
private:
std::basic_string<wchar_t> msVlu ;
public:
StringData& operator=( const wchar_t* sData )
{ msVlu = sData ; return *this ; }
operator const wchar_t*( ) const
{ return msVlu.c_str( ) ; }
public:
StringData( )
{ }
} ;