0

if m_attr.GetValue() returns a CString then:

why does the below code work without error message ... only warning message 'C4927'?

std::string sigCncDialog::GetSignalAttributeValue()
{return m_attr.GetValue();}

the correct would be of course:

std::string sigCncDialog::GetSignalAttributeValue()
{return m_attr.GetValue().GetString();}

1 Answer 1

3

Because of two evils:

  • CString has a conversion operator allowing implicit conversion to a C-style character pointer
  • the compiler apparently allows an implicit conversion sequence to contain two user-defined conversions, CString -> const char* -> std::string, with just the warning you mention, even though such a conversion is forbidden by standard C++
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.