gpt4 book ai didi

c++ - 不能从同一类的另一个构造函数调用具有所有默认参数的显式构造函数

转载 作者:行者123 更新时间:2023-11-28 06:31:34 25 4
gpt4 key购买 nike

为什么不能从同一类的另一个构造函数调用具有所有默认参数的显式构造函数?

 #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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com