小编use*_*605的帖子

c ++ 11 enable_if错误

我在C++ 11中看到了以下enable_if示例:

struct is_64_bit
{
    static const bool value = sizeof(void*) == 8;
};

enable_if<is_64_bit::value, void>::type
my_memcpy(void* target, const void* source, size_t n)
{
    cout << "64 bit memcpy" << endl;
}

enable_if<!is_64_bit::value, void>::type
my_memcpy(void* target, const void* source, size_t n)
{
    cout << "32 bit memcpy" << endl;
}
Run Code Online (Sandbox Code Playgroud)

据我了解,根据系统架构,"my_memcpy"函数可用于32位或64位版本.但是我在编译时遇到以下错误:

error: ‘type’ in ‘struct std::enable_if<false, void>’ does not name a type
Run Code Online (Sandbox Code Playgroud)

我有点困惑,因为我认为只有32版本可用(我使用的是Linux Fedora 32位).

这个例子可能有问题吗?还是我错过了什么?

谢谢.

c++ c++11

9
推荐指数
3
解决办法
6302
查看次数

gSOAP的/ Valgrind的; 没有泄漏但是内存错误

我正在使用gSoap编写Web服务客户端并使用Valgrind来检查内存问题.

Valgrind报告没有泄漏,但显示这个奇怪的(至少对我而言)内存错误消息:

==3529== Conditional jump or move depends on uninitialised value(s)
==3529==    at 0x405D6DC: soap_reference (stdsoap2.c:6926)
==3529==    by 0x405305D: soap_serialize_string (sepomexC.c:4982)
==3529==    by 0x404AF5E: soap_serialize_ns1__asentamientosPorCodigoPostalRqType (sepomexC.c:2629)
==3529==    by 0x40500F3: soap_serialize_PointerTons1__asentamientosPorCodigoPostalRqType (sepomexC.c:4103)
==3529==    by 0x4046666: soap_serialize___sep__consultarAsentamientosPorCodigoPostal (sepomexC.c:1233)
==3529==    by 0x4053A7D: soap_call___sep__consultarAsentamientosPorCodigoPostal (sepomexClient.c:186)
==3529==    by 0x40417CA: consultarAsentamientosPorCodigoPostal (main.c:73)
==3529==    by 0x804870C: main (sepomexmain.c:31)
==3529== 
==3529== Conditional jump or move depends on uninitialised value(s)
==3529==    at 0x4061AA5: soap_element_id (stdsoap2.c:9583)
==3529==    by 0x4068B0C: soap_outstring (stdsoap2.c:12681)
==3529==    by 0x4052DAE: soap_out_xsd__integer (sepomexC.c:4918)
==3529==    by 0x404B062: soap_out_ns1__asentamientosPorCodigoPostalRqType …
Run Code Online (Sandbox Code Playgroud)

c valgrind gsoap

8
推荐指数
1
解决办法
1017
查看次数

typedef和define之间的区别

可能重复:
c中的typedef和#define是否相同?
感到困惑的是#define和typedef

以下是否有任何区别:

#define NUM int

...

NUM x;
x = 5;
printf("X: %d\n", x);
Run Code Online (Sandbox Code Playgroud)

还有这个:

typedef int NUM;

...

NUM x;
x = 5;
printf("X : %d\n", x);
Run Code Online (Sandbox Code Playgroud)

两个测试都可以正常编译和运行.那么,它们是等价的吗?

谢谢.

c

5
推荐指数
1
解决办法
1万
查看次数

std ::指针列表和remove_if

我正在用std ::指针列表做一些测试.我正在使用remove_if算法来消除列表中的一些元素.但我遇到了一些问题,remove_if正在创建内存泄漏,因为它不会破坏指针(我认为).

我找到了一个解决方案,但我不知道它是否做得好,正确或至少可以接受......

这是代码:

#include <algorithm>
#include <iostream>
#include <list>

using namespace std;

class Object
{
 private:
         int intData;   
 public:
        Object(int n) : intData(n) { };
        int getIntData(void) { return intData; };
        void setIntData(int n) { intData = n; };
};

/** Functor */
struct listFunctor
{ 
 bool operator()(Object* obj1, Object* obj2) const
 {
  return (obj1->getIntData() < obj2->getIntData());
 }
};

class removeFunctor
{
 private:
         int remover;
 public:
        removeFunctor(int n) : remover(n) { };
        bool operator()(Object* obj)
        {
         bool res = …
Run Code Online (Sandbox Code Playgroud)

c++ stl

1
推荐指数
1
解决办法
1533
查看次数

标签 统计

c ×2

c++ ×2

c++11 ×1

gsoap ×1

stl ×1

valgrind ×1