Search code examples
c++typescompiler-errorstype-safety

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?


Solution

  • Use overload:

    template <typename T> void foo(T) = delete;
    
    void foo(std::size_t t) {
        // ...    
    }