so I am trying to construct a class with helper method, namely:
class Type{
int a, b, c;
friend auto helper(auto);
friend auto test_helper(auto);
/* couples test with implement */
public:
void method(){
helper(this);
}
};
But making helper
a friend function couples the test with implementation if we want to test helper
.
So I want to make helper
a free function, namely:
auto helper(int&,int&,int&);
auto test_helper(int&,int&,int&);
class Type{
int a, b, c;
public:
void method(){
helper(a,b,c);
}
};
This, however, makes the code a lot more tedious when data members are many. So, I came up with an idea to construct an helper struct that has exact data member as Type
but with all data member being public, so that we'll be able to simply pass in the handle of such HelperType
, maybe something like:
struct HelperType{
int a, b, c;
};
auto helper(HelperType* a);
auto test_helper(HelperType* a);
void Type::method(){
helper(static_cast<HelperType*>(this));
}
Is there any elegant approaches to construct such HelperType
struct? Such as a generic wrapper or perhaps with inheritance?