Do you cast the result of malloc?

This question already has an answer here: Why does C++ require a cast for malloc() but C doesn't? 3 answers In C, you can implicitly convert from a void* (the return type of malloc ) to any other pointer type. Therefore, the cast isn't required, and it's considered good C style to leave the cast off. In C++, you cannot implicitly convert from a void* to any other pointer type,

你投了malloc的结果吗?

这个问题在这里已经有了答案: 为什么C ++需要对malloc()进行强制转换,但C不是? 3个答案 在C中,可以隐式地从void* ( malloc的返回类型)转换为任何其他指针类型。 因此,演员阵容不是必需的,并且将演员阵容排除在外,被认为是C风格。 在C ++中,不能将void*隐式转换为任何其他指针类型,因此需要强制转换。 这就是说,在C ++中,你应该几乎可以肯定地使用new和delete而不是malloc ,因为它们更安全,可以很好地

Regular cast vs. static

This question already has an answer here: When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? 6 answers static_cast static_cast is used for cases where you basically want to reverse an implicit conversion, with a few restrictions and additions. static_cast performs no runtime checks. This should be used if you know that you refer to an object of a specific typ

普通投与静态

这个问题在这里已经有了答案: 什么时候应该使用static_cast,dynamic_cast,const_cast和reinterpret_cast? 6个答案 的static_cast static_cast用于基本上想要反转隐式转换的情况,只有一些限制和附加。 static_cast执行运行时检查。 如果你知道你指的是一个特定类型的对象,那么应该使用它,因此检查是不必要的。 例: void func(void *data) { // Conversion from MyClass* -> void* is implicit MyClass *

Mocking a method with throw() specifier

I am trying to Google mock a virtual method which has a throw() specifier. The original function looks like this: virtual ReturnValue FunctionName() const throw(); I am getting the compiler error: looser throw specifier for 'virtual FunctionSignature' Here is the code I have tried thus far: MOCK_CONST_METHOD0( FunctionName, ReturnValue() ); MOCK_CONST_METHOD0( FunctionName, Retu

用throw()说明符嘲笑一个方法

我正在尝试Google模拟一个具有throw()说明符的虚拟方法。 原始功能如下所示: virtual ReturnValue FunctionName() const throw(); 我得到了编译器错误: looser throw specifier for 'virtual FunctionSignature' 这是我迄今为止尝试过的代码: MOCK_CONST_METHOD0( FunctionName, ReturnValue() ); MOCK_CONST_METHOD0( FunctionName, ReturnValue() throw() ); MOCK_CONST_METHOD0( FunctionName, Retur

C++ Private Nested Abstract Class

So maybe this is a dumb question and I'm over thinking this, but I have the following situation. I am making a "class Shell" which can run abstract "class Action" objects. It is the only class that should create or use these objects. Action objects need access to the Shell to perform specific actions on it, but I'm trying to avoid adding public interfaces for this (

C ++私有嵌套抽象类

所以也许这是一个愚蠢的问题,我正在想这个,但我有以下情况。 我正在制作一个“类Shell”,它可以运行抽象的“class Action”对象。 它是唯一应该创建或使用这些对象的类。 Action对象需要访问Shell以对其执行特定的操作,但我试图避免为此添加公共接口(不应允许其他人这样做)。 我原本有一个简单的(不那么优雅) class Shell { public: bool checkThing(); // etc... private: bool _thing; }; class Actio

Why std::atomic overloads each method with the volatile

The following excerpt from the current draft shows what I mean: namespace std { typedef struct atomic_bool { bool is_lock_free() const volatile; bool is_lock_free() const; void store(bool, memory_order = memory_order_seq_cst) volatile; void store(bool, memory_order = memory_order_seq_cst); bool load(memory_order = memory_order_seq_cst) const volatile;

为什么std :: atomic会使用volatile来重载每个方法

以下摘自当前的草案显示了我的意思: namespace std { typedef struct atomic_bool { bool is_lock_free() const volatile; bool is_lock_free() const; void store(bool, memory_order = memory_order_seq_cst) volatile; void store(bool, memory_order = memory_order_seq_cst); bool load(memory_order = memory_order_seq_cst) const volatile; bool load(memory_orde

Accessing real and imaginary parts of a complex number

When debugging a program which uses (either C or C++), gdb displays complex numbers as _M_value = xxx + yyy*I (with a type of complex double ). While debugging, I need to print that number multiplied by a factor. The following does not work: print a * 8.0 I get Argument to arithmetic operation not a number or boolean . Also, I cannot access the real and imaginary parts so that I can write

访问复数的实部和虚部

在调试使用(C或C ++)的程序时, gdb显示复数为_M_value = xxx + yyy*I (带有一个complex double _M_value = xxx + yyy*I型)。 在调试时,我需要打印该数字乘以一个因子。 以下不起作用: print a * 8.0 我得到的Argument to arithmetic operation not a number or boolean 。 另外,我不能访问实部和虚部,以便我可以编写一个gdb宏来完成上述操作。 我目前的解决方案是编写一个C函数来处理复杂的值和数组,并从gdb

gdb: internal error setting breakpoints

My program is compiled with the -g flag. I am having the following problem: 1) I have set a breakpoint in a function that is in a header file. The breakpoint works. Now, when I go two level up, it is supposed to take me to a C file (Sizer.C:505). It does, but I get loads of warnings: warning: (Internal error: pc 0xff6323 in read in psymtab, but not in symtab.) warning: (Internal error: pc

gdb:内部错误设置断点

我的程序是用-g标志编译的。 我遇到以下问题: 1)我在一个头文件中的函数中设置了一个断点。 断点起作用。 现在,当我升到两级时,它应该把我带到一个C文件(Sizer.C:505)。 它的确如此,但我收到了很多警告: warning: (Internal error: pc 0xff6323 in read in psymtab, but not in symtab.) warning: (Internal error: pc 0xff6324 in read in psymtab, but not in symtab.) warning: (Internal error: pc 0xff6323

Need help implementing a special edge detector

I'm implementing an approach from a research paper. Part of the approach calls for a major edge detector, which the authors describe as follows: Obtain DC image (effectively downsample by 8 for both width and height) Calculate Sobel gradient of DC image Threshold Sobel gradient image (using T=120) Morphological operations to clean up edge image Note that this NOT Canny edge detecti

需要帮助实施特殊的边缘检测器

我正在从一篇研究论文中实施一种方法。 部分方法需要一个主要的边缘检测器,作者描述如下: 获取DC图像(对于宽度和高度都有效地缩减8) 计算DC图像的Sobel梯度 阈值Sobel梯度图像(使用T = 120) 形态学操作清理边缘图像 请注意,这不是 Canny边缘检测 - 它们不会打扰非最大抑制等事情。我当然可以用Canny边缘检测来做到这一点,但我希望按照文中所表达的内容来实现。 最后一步是我有点卡住了。 这正是作者对此

Implicit conversion for pointer to data member vs. non

Most discussion I've seen about member pointers focus on conversions permitted on the type to which the member belongs. My question is about conversions on the type of the member. struct Base{}; struct Derived : public Base{}; struct Foo{ Derived m_Derived; }; Given these declarations, the following code produces an error (MSVC 2008): // error C2440: 'initializing' : cannot convert from '

隐式转换为指向数据成员与非指针的指针

关于成员指针的大部分讨论都集中在成员所属的类型上允许的转换。 我的问题是关于成员类型的转换。 struct Base{}; struct Derived : public Base{}; struct Foo{ Derived m_Derived; }; 鉴于这些声明,以下代码会产生错误(MSVC 2008): // error C2440: 'initializing' : cannot convert from 'Derived Foo::* ' to 'Base Foo::* ' Base Foo::*p = &Foo::m_Derived; 从Derived *到Base *的转换通常是允许的 - 为什么

Face recognition and aging faces in c++

Hello I'm looking for some good library (opensource) that allows me to do face recognition and to easily aging faces. Take a look for example at: http://www.in20years.com/ I need some library cross platform (not just for windows), and I would integrate that code into some iPhone Applications. Any Suggestions? Many thanks! A basic image processing and computer vision library is OpenC

面部识别和老化的面孔在c + +

你好我正在寻找一些好的图书馆(开源),让我做脸识别和容易老化的面孔。 看看例如:http://www.in20years.com/ 我需要一些库跨平台(而不仅仅是Windows),我会将这些代码集成到一些iPhone应用程序中。 有什么建议么? 非常感谢! 基本的图像处理和计算机视觉库是OpenCV。 这是首先要考虑的事情,但真诚 - 不要期望已经实现了所有你需要的东西。 有一些面部识别API提供者。 Face ++是唯一一个提供所有免费在线AP