A collision mask would be visualed as a line of binary bits:
11001011
Each density variable would use it like that. I figure most games is already adapted since only 0 and 1 can be used for density. Anywho, here are my examples:
A body:
density=1 (01)
An intangible ghost:
density=2 (10)
A wall:
density=1 (01)
A ghost-proof wall:
density=3 (11)
The ghost may pass walls, but the solid body may not. The ghost may also not pass through the enchanted wall.
The numbers of the two colliding objects would be ANDed together. If true, the object if blocked, else it may pass.
11010000
-and-
00101111 // May pass
10000000 // May not pass
00000000 // May pass anything
11111111 // May not pass anything (If the density max was 255)
I've never used C++ before, but I'd suppose just an && would be nneeded to be changed to &, and the ability to use other numbers with density to be enabled.