The following code compiles without any warning or error on G++ (GCC) 4.1.2.
Is there a reason for not issuing an error/warning?
Is there a flag that can cause it to issue a warning or error?
#include <iostream>
using namespace std;
void func(string &s)
{
unsigned long u = 123;
s = u;
}
int main()
{
string s;
func (s);
return 0;
}
The reason there’s no warning or error is because this is valid C++.
std::stringoverloads the assignment operator (operator=) to take achar.longcan be implicitly converted to achar, hence the code makes sense.