I am trying to create a class called Sinkthat will create a pointer to the class you are going to, this is the api shell in RAII.
In the full version of this code, the user class is also inherited from another class, and there are static assets for verification. The pointer is also passed to api.
But to make it simple, I deleted it.
This is the error I get from cpp.sh
In function 'int main()':
43:30: error: no matching function for call to 'Sink<OneArg>::Sink(int)'
43:30: note: candidate is:
10:5: note: Sink<CustomSink, Args>::Sink(Args&& ...) [with CustomSink = OneArg; Args = {}]
10:5: note: candidate expects 0 arguments, 1 provided
The code:
template<typename CustomSink, typename... Args>
class Sink
{
public:
Sink(Args&&... args)
{
_ptr = std::make_unique<CustomSink>(std::forward<Args>(args)...);
}
~Sink()
{
}
private:
std::unique_ptr<CustomSink> _ptr;
};
//////////////////////////////////////////////////////////////////////
class NoArg
{
public:
NoArg() {};
~NoArg() {};
};
class OneArg
{
public:
OneArg(int a) {
std::cout << a << '\n';
};
~OneArg() {};
};
//////////////////////////////////////////////////////////////////////
int main(){
Sink<NoArg> noArgSink;
Sink<OneArg> oneArgSink(5);
return 0;
}
source
share