草庐IT

Hash_class

全部标签

c++ - 为什么 injected-class-name 有时不被视为类模板中的模板名称?

SourceInthefollowingcases,theinjected-class-nameistreatedasatemplate-nameoftheclasstemplateitself:itisfollowedbyitisusedasatemplateargumentthatcorrespondstoatemplatetemplateparameteritisthefinalidentifierintheelaboratedclassspecifierofafriendclasstemplatedeclaration.所以我尝试检查所有3种情况(另外在基本歧义的情况下,尽管我

c++ - 对齐 : warning C4316 in all classes that have aligned members

今天我遇到了很多麻烦,因为我跟踪了一个非常隐蔽的腐败漏洞。我想如果我真的注意警告就不会那么难找到它,但由于找不到有关为什么弹出此特定警告的相关信息,我让它滑动了,这是一个错误。所以这是VisualStudio2013给我的有罪警告:warningC4316:objectallocatedontheheapmaynotbealigned16它是在通过const引用将align(16)临时传递给构造函数时生成的,如以下代码所示:classVector{};__declspec(align(16))classVectorA{};classShape{public:Shape(constVec

c++ - 从 boost::hash 获取 32 位哈希值

我正在使用boost::hash获取字符串的哈希值。但它在Windows32位和Debian64位系统上为相同的字符串提供了不同的哈希值。那么如何使用boost::hash获得相同的哈希值(32位或64位)而不考虑平台? 最佳答案 关于boost::hash的保证是什么?我没有看到任何保证生成的哈希码在外部可用产生它的过程。(这种情况经常发生散列函数。)如果您需要外部数据的散列值,在不同的程序和不同的平台上有效(例如对磁盘上数据的哈希访问),那么你必须编写你的自己的。像这样的东西:uint32_thash(std::stringco

distribute by hash

建表语句:createtablexxx.CCRD_CUSTR_HIS( BG_DT_ZCCDATEnotnull, ED_DT_ZCCDATEnotnull, CUSTR_NBRVARCHAR(19)notnull, RACE_CODEVARCHAR(2), CUSTR_REFVARCHAR(20), primarykey(BG_DT_ZCC,ED_DT_ZCC,CUSTR_NBR))distributebyhash(BG_DT_ZCC,ED_DT_ZCC,CUSTR_NBR);commentontablexxx.CCRD_CUSTR_HISis'客户基本资料';commentoncolumn

c++ - GMock : How to return mock class variable as the return value

我是第一次尝试使用GMock(用于C++的谷歌模拟框架)。我有以下类(class):classLocalCache{public:virtualtime_tGetCurrentTime()=0;virtualintAddEntry(conststd::stringkey,std::string&value);virtualintGetEntry(conststd::stringkey,std::string&value);};GetEntry方法调用GetCurrentTime调用。我想模拟GetCurrentTime方法,以便我可以在测试中提前时钟以测试作为GetEntry调用的一部

c++ - 为什么 Builder 模式比在正在创建的 Class 对象中带有参数的 Constructor 更好?

为什么我们不能在构造函数本身中执行不同的构建步骤。如果构建步骤采用参数,为什么不能将它们作为参数提供给构造函数并在构造函数中用于创建对象。据我所知,在Builder模式中,客户端要创建哪个特定对象;那么在正在创建的类的对象中使用构建器而不是带有参数的构造函数有什么优势? 最佳答案 哦!我得到它。我正在查看维基百科示例并意识到Builder为何有用。当客户端不知道将哪些参数传递给构造函数时,这很有用,因为它非常复杂,因此无法直接调用构造函数并获取对象。因此,他向ConcreteBuilders寻求帮助,他们知道将哪些参数传递给构造函数

c++ - 移动构造函数和赋值运算符 : why no default for derived classes?

为什么没有为派生类创建默认移动构造函数或赋值运算符?证明我的意思;具有此设置代码:#includestructA{A(){}A(A&&){throw0;}A&operator=(A&&){throw0;}};structB:A{};以下任一行抛出:Ax(std::move(A());Ax;x=A();但以下都没有:Bx(std::move(B());Bx;x=B();以防万一,我使用GCC4.4进行了测试。编辑:后来使用GCC4.5进行的测试显示了相同的行为。 最佳答案 通读0xFCD中的12.8(12.8/17特别是移动构造函数)

c# - "C# base class virtual function"- "override in Managed C++ ref class"

我有一个.NET_4ManagedC++ref类,它派生自用C#编写的.NET_4基类。C#基类:namespaceCore{publicclassResourceManager{publicclass_Resource{publicvirtualvoidDelete(){}}}}托管C++类:namespaceInput.DI{publicrefclassMouse:ResourceManager::_Resource{public:virtualvoidDelete(){}};}这是我遇到的错误:'Input::DI::Mouse::Delete':matchesbaserefcl

c++ - 多重继承 : size of class for virtual pointers?

给定代码:classA{};classB:publicvirtualA{};classC:publicvirtualA{};classD:publicB,publicC{};intmain(){cout输出:sizeof(D)8每个类都包含自己的虚指针,但不包含其任何基类的虚指针,那么,为什么class(D)的Size是8? 最佳答案 这取决于编译器的实现。我的编译器是VisualStdioC++2005。代码如下:intmain(){cout会输出sizeof(B):4sizeof(C):4sizeof(D):8B类只有一个虚指针

c++ - 是否可以将作用域枚举 ("enum class") 上下文转换为 bool 值?

假设我有enumclassFlags:std::uint16_t{None=0,A=0x0001,B=0x0002,C=0x0004}inlineFlagsoperator|(Flagslhs,Flagsrhs){returnstatic_cast(static_cast(lhs)|static_cast(rhs));}inlineFlagsoperator&(Flagslhs,Flagsrhs){returnstatic_cast(static_cast(lhs)&static_cast(rhs));}inlineFlagsoperator|=(Flags&lhs,Flagsrhs)