24 June 2017
Port 80
Unexpected leftover from C hits back.
Code sample
1
2
3
4
5
6
7
8
9
#include <string>
#include <iostream>
int main()
{
std::string x;
x += ":" + 80;
std::cout << x << "\n";
}
It should not compile (or at least it should give a warning). Yet it does; on my system it prints āiā. I rest my case.
Once you figure out what happens: I wonder if fundamentally this is caused by
literals not being separate types, e.g. ":"
is a const char(&)[2]
which
decays toconst char *
, 80
is an int
, rather than separate types from
objects a
or b
as in const char * a;
or int b;