相关疑难解决方法(0)

您自己的类型的结构化绑定,不是结构或元组(通过公共成员函数)

我正在经历Herb Scutter的

旅程:走向更强大,更简单的C++编程

结构绑定部分

为了理解这个概念.Best是编写一个我试过的程序,但是遇到了一些错误

只是想尝试如何在类上使用私有数据的结构绑定.请忽略下面的示例.如果您能提供任何示例

#include<iostream>
#include<string>
using namespace std;

class foobar {
public:
    foobar() { cout << "foobar::foobar()\n"; }
    ~foobar() { cout << "foobar::~foobar()\n"; }

    foobar( const foobar &rhs )
    { cout << "foobar::foobar( const foobar & )\n"; }
    void ival( int nval, string new_string ) { _ival = nval;s=new_string; }

private:
    int _ival;
    string s;
};

foobar f( int val,string new_string ) {
    foobar local;
    local.ival( val,new_string );
    return local;
}

template<> struct tuple_element<0,foobar> { using …
Run Code Online (Sandbox Code Playgroud)

c++ stdtuple c++17 structured-bindings if-constexpr

7
推荐指数
2
解决办法
1553
查看次数

标签 统计

c++ ×1

c++17 ×1

if-constexpr ×1

stdtuple ×1

structured-bindings ×1