This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] Compiler/66AK2H12:Compiler C6000 8.2 (编译器C6000系列)_1 hash_set issue (1哈希集问题)

Guru**** 2337880 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/619999/compiler-66ak2h12-compiler-c6000-8-2-1-hash_set-issue

部件号:66AK2H12

工具/软件:TI C/C++编译器

你(们)好

我编写了以下代码:

#include <hash_set>

结构X

};

typedef std::hash_set<X*,std::hash<X*>,std::equate_to <X*>,
std::allocator<X*> AllocatedBlocksSet;
AllocatedBlocksSet t;


typedef std::hash_set<void*,std::hash<void*>,std::eque_to_<void*>,
std::allocator<void*> VoidPtrBlocksSet;
VoidPtrBlocksSet T1;

void func()

x*转台;
t.insert(ret);
}

void function1()函数

x*转台;
t1.insert((void*)ret);
}

func()失败,并显示以下错误: “c:\ti/ccsv6/tools/compiler/C6000_fashtable.1/include/s__hashtable.h 8.2 ”,第617行:错误#1034:调用没有适当运算符()或转换函数的类类型的对象到指针到函数类型

功能1不会失败

x*和void*都是指针,因此为什么一个编译而另一个不编译

谢谢

白安

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    TI编译器目前支持1998/1999年1999年的C++标准(C++98/03)。

    STD::hash和std::hash_set不是本标准的一部分,它们作为标准库的不可移植扩展提供。

    我们的std::hash扩展版本特别具有以下相关专业:

    template <class _Key> struct hash {};(模板<class _Key>结构散列

    struct hash<char*>//定义operator()

    struct hash<const char*>//定义operator()

    struct hash<void *>//定义operator()

    请注意,缺省实例化没有要调用的operator()。


    您的示例代码将生成std::hash<X*>,该代码不适合任何定义的专业化。 这会导致使用缺省的专业化,并且基础hash_set实现失败,因为没有运算符(),它可以用来对指针进行散列。

    我建议您使用std::hash<void*>哈希X*对象。 或者,您可以定义自己的std::hash专业化,如下所示:

    名称空间标准{
    template<>结构散列<X*>{
    size_t operator()(X *val) const {
    return (size_t)val;
    }
    };
    }