【发布时间】:2015-02-10 16:36:12
【问题描述】:
为什么不能从同一个类的另一个构造函数中调用具有所有默认参数的显式构造函数?
#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()’
【问题讨论】:
-
我使用的是g++ 4.8.2版
-
在 g++ 4.9.1 中运行良好
标签: c++ constructor explicit