static_cast vs dynamic_cast: undefined behavior

| category: Programming | author: st
Tags:

Do not use static_cast when you cast from a basic class to a derived one. This may lead to undefined behavior. To handle the polymorphism, a virtual inheritance or a multiple inheritance case always use dynamic_cast instead.

The following short example shows the undefined behavior cases. This works with GCC …

Qt Test limitations and workarounds

| category: Testing | author: st
Tags:

Pros and cons

Why use Qt Test for unit testing and TDD (test-driven development)?

  • small testing framework (about 6K lines of source code);
  • seamless integration with QtCreator development environment;
  • full support of Qt framework including classes/types and signal/slots;
  • simple to start and use.

However, there are some drawbacks …

SQL Server: kill all database connections

| category: Programming | author: st
Tags:

How to kill all database connections before dropping it?

USE master;
GO
DECLARE @sql nvarchar(max);
WHILE 1=1 BEGIN
    SELECT TOP 1 @sql = N'KILL ' + convert(nvarchar(10), spid)
    FROM sysprocesses WHERE dbid = DB_ID('my_database');
    IF @@rowcount = 0  BREAK;
    EXEC sp_executesql @sql;
END;
DROP DATABASE IF EXISTS my_database;

C++11 constructors

| category: Programming | author: st
Tags: ,

According to specification, "...constructor is a special non-static member function of a class that is used to initialize objects of its class type". In addition to basic concepts, C++11 introduces move constructors, initializer list type and brace-enclosed lists of comma-separated initializers.

However the impact of introducing new constructors combining …