Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function that takes one explicit type

How can I make a function that accepts, for example, a size_t but does NOT accept an int or any other implicitly convertible type?

like image 484
Andreas Loanjoe Avatar asked Sep 19 '26 12:09

Andreas Loanjoe


1 Answers

Use overload:

template <typename T> void foo(T) = delete;

void foo(std::size_t t) {
    // ...    
}
like image 120
Jarod42 Avatar answered Sep 21 '26 02:09

Jarod42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!