我正在经历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)