相关疑难解决方法(0)

基于模板参数类型调用函数

有两个"C"功能:

void fooA(const char*);
void fooW(const wchar_t*);
Run Code Online (Sandbox Code Playgroud)

然后有一个包装模板函数:

template<typename _TChar>
void foo(const _TChar* str)
{
     // call fooA or fooB based on actual type of _TChar
     // std::conditional .. ?
         // fooA(str); 
         // fooW(str);
}
Run Code Online (Sandbox Code Playgroud)

如果调用者调用foo("Abc"),则此模板函数应进行编译时调用fooA.同样,foo(L"Abc")应该做最后的调用fooW.

我怎么做?我想过使用std::conditional但不能成功.

我无法制作fooAfooB过载,因为这些是C函数.

c++ visual-c++ c++11 c++14

17
推荐指数
4
解决办法
5438
查看次数

标签 统计

c++ ×1

c++11 ×1

c++14 ×1

visual-c++ ×1