I am playing around with converting standard library functions like stoi
to not throw exceptions on failures but keep running into linking issues. I followed steps from other similar questions but the linker is still not satisfied
Header.h
#include <optional>
#include <iostream>
#include <string>
#include <cstddef>
namespace temp{
template<class T>
std::optional<int> noexcept_stoi( const T& str, std::size_t* pos = nullptr, int base = 10)
{
//body of the function
}
template<> inline std::optional<int> noexcept_stoi<std::wstring>( const std::wstring& str, std::size_t* pos, int base );
template<> inline std::optional<int> noexcept_stoi<std::string>( const std::string& str, std::size_t* pos, int base );
};
Test.cpp
#include "Header.h"
int main(){
std::string input = "123";
auto result = temp::safe_stoi(input);
return 0;
}
Error: Undefined symbols for architecture arm64: "std::__1::optional temp::noexcept_stoi<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > >(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, unsigned long*, int)"
What am I missing ?