You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.3 KiB

Guide to modern C++

C++20

  • Error :
    • C2664 - cannot convert ... 'const[4] to char*'
    • C2132 expression didnot evalute to a constant
void myFn(char* data)
{
    std::cout << data;
    return;
}

int main()
{
    myFn("ABC");  ==> error
    myFn(const_cast<char*>("ABC"));  ==> OK
    std::cout << "Hello World!\n";
}

constexpr struct stIniEnumToFilenameMap LogNameMap[] =
{
    {CFileLocation::DEBUG_LOG,        const_cast<TCHAR*>("Dbg.log")},
    {CFileLocation::DEBUG_TIMING_LOG, const_cast<TCHAR*>("DbgTiming.log"},
    {CFileLocation::GUIEVENT_LOG,     const_cast<TCHAR*>("GUIEventLog.log"},
};
  • range for loop for each()

for each (auto x in items){}  ==> error

for (auto x : items) {} ==> OK
  • Error: C2440 'initializing': cannot convert from 'ATL::CA2CA' to 'std::basic_string<char,std::char_traits,std::allocator>'
std::string strModelName = hardwareIniMotionCard.GetString(osKey.str().c_str(), "Error", FALSE).GetString();  ==> OK - use CString().GetString()