次のコードを clang 3.5.0 および gcc 4.9.1 でコンパイルすると、最後のステートメントでエラーが発生します。
#include <iostream>
struct Foo { Foo(int x, int y) { std::cout << "Foo(int = " << x << ", int = " << y << ")" << std::endl; } };
void bar(int x, int y) { std::cout << "bar(int = " << x << ", int = " << y << ")" << std::endl; }
int main()
{
Foo({}, {}); // Foo(int = 0, int = 0)
Foo({1}, {2}); // Foo(int = 1, int = 2)
Foo({1, 2}); // Foo(int = 1, int = 2)
bar({}, {}); // bar(int = 0, int = 0)
bar({1}, {2}); // bar(int = 1, int = 2)
bar({1, 2}); // error: no matching function for call to 'bar' <<< Why? <<<
}
なぜFoo({1, 2})
大丈夫なのに大丈夫でbar({1, 2})
はないのですか?
特に、理論的根拠について学ぶことは素晴らしいことです。