Why do I get an exception when passing “null” constant but not when passing a “null” string reference?

Just decompile the code to work out what’s going on. string.Format(“{0}”, null) calls the most specific applicable overload, which is string.Format(string, object[]). The overloads of string.Format are: Format(String, Object) Format(String, Object[]) Format(IFormatProvider, String, Object[]) Format(String, Object, Object) Format(String, Object, Object, Object) Hopefully it’s obvious why the last three options are invalid. To work out which … Read more

How to reference Microsoft.Office.Interop.Excel dll?

Use NuGet (VS 2013+): The easiest way in any recent version of Visual Studio is to just use the NuGet package manager. (Even VS2013, with the NuGet Package Manager for Visual Studio 2013 extension.) Right-click on “References” and choose “Manage NuGet Packages…”, then just search for Excel. VS 2012: Older versions of VS didn’t have … Read more

Is there a nice way to assign std::minmax(a, b) to std::tie(a, b)?

You can use an initializer list for minmax: std::tie(a, b) = std::minmax({a, b}); This causes temporary objects to be created, just like when using unary plus, but has the benefit that it works with types lacking the unary plus operator too. using namespace std::string_view_literals; auto [a, b] = std::make_pair(“foo”sv, “bar”sv); std::tie(a, b) = std::minmax({a, b}); … Read more

c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)

If you will place your definitions in this order then the code will be compiled class Ball; class Player { public: void doSomething(Ball& ball); private: }; class Ball { public: Player& PlayerB; float ballPosX = 800; private: }; void Player::doSomething(Ball& ball) { ball.ballPosX += 10; // incomplete type error occurs here. } int main() { … Read more