This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DLP SDK with Visual Studio 2017

Has anybody come across a good/elegant way of fixing this code when compiling in Visual Studio 2017?   I saw a reference to this article which seems similar but not quite the same.....dlp::Number is a template that is called by a template, etc for several layers up the stack.  When I look at the "fix" in this article, I get the same errors further up the call stack.

 

/** @brief Contains common functions to convert numbers to strings
* @ingroup group_Common
*/
namespace Number{

/** @brief Converts a numerical variable to its ASCII string equivalent */
template <typename T>
std::string ToString( T number ){
std::ostringstream ss;
ss << std::setprecision(NUM_TO_STRING_PRECISION);
ss << number;
return ss.str();
}

template <> std::string ToString<std::string>( std::string string );
template <> std::string ToString<char>( char number );
template <> std::string ToString<unsigned char>( unsigned char number );

}


Error C2593 'operator <<' is ambiguous C:\junk\VisualStudioLightCrafterSDKx86\include\common\other.hpp DLP_SDK 220 Build

Error C2088 '<<': illegal for class C:\junk\VisualStudioLightCrafterSDKx86\include\common\other.hpp DLP_SDK 220 Build

  • Hello David,

    It looks like the << operator is not recognized in the environment you are using. Perhaps you can research the alternative function your environment is expecting. I believe << is left shift but you will want to confirm. Unfortunately we are not able to officially support alternative environments. Perhaps another user with more experience could chime in.

    Thanks,
    Kyle
  • The << operator is the C++ insertion operator for streams (as well as left shift). I fixed the issue by changing the code to this:

    namespace Number{

    /** @brief Converts a numerical variable to its ASCII string equivalent */
    template <typename T>
    std::string ToString( T number ){
    std::string templatetype;
    std::ostringstream ss;
    char buffer[50];
    //ss << std::setprecision(NUM_TO_STRING_PRECISION);
    //ss << number;
    templatetype = typeid(T).name();
    if (templatetype.compare("bool") == 0)
    ss << (int)number;
    else if (templatetype.compare("unsigned int") == 0)
    ss << (unsigned int)number;
    else if (templatetype.compare("float") == 0)
    {
    sprintf(buffer, "%f", number);
    ss << buffer;
    }
    else
    ss << typeid(T).name(); // I haven't run across any other types but if I do, print out the type I need to make a case for
    return ss.str();
    }

    It's not a terribly elegant solution and completely bypasses the whole template concept ... but it works fine and was a quick resolution to my issue.....and most importantly, produces the same results as the original code compiled with the MinGW makefiles and gcc/g++ compiler.
  • Thanks for letting us know about the solution!

    -Kyle