首页 > 解决方案 > 模板错误的演员表对象

问题描述

我有以下问题。有一个功能:

int main()
{
   //...
   std::string test = "1234";
   std::string result = ValueToCharArray(test);
   //...
}
template<class Type>
std::string ValueToCharArray(Type& value)
{
    std::string buffer = "";
    //...
    if (typeid(std::string) == typeid(value))
    {
        std::cout << typeid(std::string).name() << '\n' << typeid(value).name() << '\n';
        value.at(0);
        //...
    }
    short int i = 0;
    while (i<3)
    {
        buffer += '?';
        i++;
    }
    buffer[i] = 0;
    return buffer;
}

如果我传输字符串编译器给我下一个问题: 屏幕

错误 C2039: at: not member "std::basic_istream<char,std::char_traits>" typetostring.h(对不起语言)

如果我从值变量“ValueToCharArray(类型值)”中删除链接,我会收到下一个错误:

错误 C2280:“std::basic_ostream<char,std::char_traits>::basic_ostream(const std::basic_ostream<char,std::char_traits> &)”:您无法在已删除函数中获取链接

当字符串类型命中函数时,我需要处理它。VS说我这种类型是std :: ostream但是这个函数链接......

注意!可以使用 c++11 或 c++14。函数重载。不建议更改 fx 调用。您不能为字符串类型创建单独的函数。我将感谢所有至少提供一点帮助的人。对不起语言:D

标签: c++11templatestypescasting

解决方案


推荐阅读