为什么不能从同一类的另一个构造函数调用具有所有默认参数的显式构造函数?
#include <iostream>
#include <string>
class A {
public:
explicit A(int a = 1, int b = 2) :
a_(a),
b_(b) {}
A(std::string s)
: A() {
std::cout << s;
}
int a_;
int b_;
};
int main() {
A a("!");
std::cout << a.a_;
}
g++ -v
gcc 版本 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
g++ -o out -std=c++11 main.cpp
错误:main.cpp:12:13: 错误:没有匹配函数来调用‘A::A()’
最佳答案
看起来像是 4.9.0 中修复的 gcc 错误:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58255
关于c++ - 不能从同一类的另一个构造函数调用具有所有默认参数的显式构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27435640/