所以我试图用辅助方法构造一个类,即:
class Type{
int a, b, c;
friend auto helper(auto);
friend auto test_helper(auto);
/* couples test with implement */
public:
void method(){
helper(this);
}
};
但是helper
,如果我们想测试,创建一个朋友函数会将测试与实现结合起来helper
。
所以我想做helper
一个免费的功能,即:
auto helper(int&,int&,int&);
auto test_helper(int&,int&,int&);
class Type{
int a, b, c;
public:
void method(){
helper(a,b,c);
}
};
然而,当数据成员很多时,这会使代码变得更加乏味。所以,我想出了一个想法来构建一个辅助结构,它具有精确的数据成员,Type
但所有数据成员都是公共的,这样我们就可以简单地传递这样的句柄HelperType
,也许是这样的:
struct HelperType{
int a, b, c;
};
auto helper(HelperType* a);
auto test_helper(HelperType* a);
void Type::method(){
helper(static_cast<HelperType*>(this));
}
有没有什么优雅的方法来构造这样的HelperType
结构?例如通用包装器或可能具有继承?