Reputation:
Suppose I have a class Foo
like this:
struct Foo {
int a;
int b;
};
Then I define a second class:
struct Bar {
Foo bar{1, 2}; // error C2661: no overloaded function takes 2 arguments
};
The code Foo bar{1, 2}
works fine if bar
is not a class member:
int main() {
Foo bar{1, 2}; // OK
}
Is there anything wrong in the code of class Bar
?
Upvotes: 3
Views: 3430
Reputation: 7080
There's nothing wrong with your code. It's a compiler bug.
Both clang++ and g++ process these qualified list initializers correctly. See http://coliru.stacked-crooked.com/a/5d45e3645eec0476 for g++ demonstrating correct behavior.
Upvotes: 3