When should I really use noexcept?

The noexcept keyword can be appropriately applied to many function signatures, but I am unsure as to when I should consider using it in practice. Based on what I have read so far, the last-minute addition of noexcept seems to address some important issues that arise when move constructors throw. However, I am still unable to provide satisfactory answers to some practical questions that led me t

我应该什么时候使用noexcept?

noexcept关键字可以适用于许多功能签名,但我不确定何时应该考虑在实践中使用它。 根据我目前阅读的内容, noexcept的最后一刻添加似乎解决了移动构造函数抛出时出现的一些重要问题。 但是,我仍然无法为一些实际问题提供令人满意的答案,这些问题让我首先阅读了更多关于noexcept的内容。 有很多函数的例子,我知道永远不会抛出,但编译器无法自行确定。 在所有这些情况下,我是否应该在函数声明中添加noexcept ? 不得不

looser throw specifier for in C++

I am getting an error that says: error: looser throw specifier for 'virtual CPLAT::CP_Window::~CP_Window()' On the destructor, I have never heard of this before and some Google Searches say this might be a GCC 4 problem, which I would not be sure how to work around since I need GCC 4 to build a Universal Binary. My Environment: OS X 10.6, XCode 3.2.2, GCC 4 to build a universal bina

在C ++中宽松抛出说明符

我收到一个错误,说: 错误:'虚拟CPLAT :: CP_Window ::〜CP_Window()'的宽松抛出说明符' 在析构函数中,我从来没有听说过这个,一些Google搜索表示这可能是一个GCC 4问题,我不知道如何解决,因为我需要GCC 4来构建一个通用二进制文件。 我的环境:OS X 10.6,XCode 3.2.2,GCC 4构建通用二进制文件。 什么是问题? 我认为CPLAT有一个基类? 我还猜测你没有在CPLAT的析构函数中加上一个throw说明符?

virtual methods in C++ without editing production code?

I am a fairly new software developer currently working adding unit tests to an existing C++ project that started years ago. Due to a non-technical reason, I'm not allowed to modify any existing code. The base class of all my modules has a bunch of methods for Setting/Getting data and communicating with other modules. Since I just want to unit testing each individual module, I want to be a

C ++中的虚拟方法,无需编辑生产代码?

我是一个相当新的软件开发人员,目前正在将单元测试添加到多年前开始的现有C ++项目中。 由于非技术原因,我不允许修改任何现有的代码。 我所有模块的基类都有一些设置/获取数据和与其他模块通信的方法。 由于我只想对每个单独的模块进行单元测试,因此我希望能够为我的所有模块间通信方法使用固定值。 也就是说,Ping()方法检查另一个模块是否处于活动状态,我希望根据我正在做什么类型的测试返回true或false。 我一直

My programs are blocked by avast anti

I'm an amateur programmer, and I'm getting desperate and mad because of a big issue: most of my programs are blocked by avast anti-virus, while some aren't, and I don't understand why. The more I try to investigate, the less I understand what the problem could be. I'm requesting your help to find a solution so that my programs are no longer blocked, or, as a default, at lea

我的程序被avast反封锁

我是一名业余程序员,因为一个大问题我正在陷入绝望和疯狂:我的大部分程序都被avast反病毒拦截,有些则不是,我不明白为什么。 我试图调查的越多,我就越不了解问题所在。 我请求你的帮助来找到一个解决方案,以便我的程序不再被阻止,或者作为默认,至少有一些强大的线索可以解释为什么它可能是这种情况。 网络上已经有很多关于这方面的话题。 然而,他们大多只给出一些肤浅的答案:他们只是解释了反病毒如何与签名和检测

Passing callback function to thread in C++/CLI

Some context: I know basic C++. For the first time, I'm trying to create GUI application in Visual Studio using C++/CLI. However, I can't find much answers online about the latter. I've got to classes: MyForm , the main class corresponding to a Windows Form, and OtherClass . MyForm has an object of type OtherClass as a member. A function of MyForm , in this example myButton_Clic

将回调函数传递给C ++ / CLI中的线程

一些上下文:我知道基本的C ++。 我第一次尝试使用C ++ / CLI在Visual Studio中创建GUI应用程序。 但是,我无法在网上找到关于后者的很多答案。 我有类: MyForm ,与Windows窗体和OtherClass相对应的主类。 MyForm有一个类型为OtherClass的对象作为成员。 MyForm一个函数,在这个例子中myButton_Click ,初始化这个对象并在一个线程中调用它的一个函数: using namespace System::Threading; ref class MyForm; ref clas

Pointer to a pointer C++/CLI wrapper

I am trying to write a managed C++/CLI wrapper to unmanaged class. One of the methods in the class has a signature like audiodecoder::Decode(byte *pEncodedBuffer, unsigned int uiEncodedBufLen, byte **pDecodedAudio, unsigned int *uiDecodedAudioLen) where *pEncodedBuffer is pointer to encoded audio sample and **pDecodedAudio is where the function would initialize memory and store the decoded aud

指向C ++ / CLI包装器的指针

我正在尝试编写托管C ++ / CLI包装到非托管类。 其中一种方法有类似的签名 audiodecoder::Decode(byte *pEncodedBuffer, unsigned int uiEncodedBufLen, byte **pDecodedAudio, unsigned int *uiDecodedAudioLen) 其中* pEncodedBuffer是编码音频采样的指针,** pDecodedAudio是函数初始化内存并存储解码音频的位置。 事实上,数据是音频应该是没有任何意义的。 这个方法的包装会如何? 任何建议都会有所帮助。 托管代

Change Protected Method From Abstract Class to Private In Concrete Class

I want to create an abstract class with a pure virtual private method but I can't implement that in my concrete class. My option is to make that pure virtual private method to protected but in my concrete class I want to make it only a private. Like, class IFoo { public: IFoo(){} virtual ~IFoo(){} protected: virtual void fooMethod() = 0; }; class Foo : public IFoo { public:

将受保护的方法从抽象类更改为私有混凝土类

我想创建一个具有纯虚拟私有方法的抽象类,但是我无法在具体的类中实现它。 我的选择是使这种纯粹的虚拟私人方法得到保护,但在具体的课堂上,我想让它只是一个私人的方法。 喜欢, class IFoo { public: IFoo(){} virtual ~IFoo(){} protected: virtual void fooMethod() = 0; }; class Foo : public IFoo { public: Foo(){} virtual ~Foo(){} private: virtual void fooMethod() {} }; 有没有

Why does C++ not allow inherited friendship?

Why is friendship not at least optionally inheritable in C++? I understand transitivity and reflexivity being forbidden for obvious reasons (I say this only to head off simple FAQ quote answers), but the lack of something along the lines of virtual friend class Foo; puzzles me. Does anyone know the historical background behind this decision? Was friendship really just a limited hack that has

为什么C ++不允许继承友谊?

为什么友谊至少不能在C ++中继承? 我明白传递性和反身性因为显而易见的原因被禁止(我说这只是为了阻止简单的常见问题引用答案),但是缺乏类似于virtual friend class Foo; 困惑我。 有人知道这个决定背后的历史背景吗? 友谊真的只是一个有限的黑客,因为它已经找到了一些晦涩的可敬的用途? 编辑澄清:我在谈论以下场景,而不是A的孩子接触B或B和它的孩子。 我还可以设想可以选择授予对朋友函数等的覆盖访问权限。 cl

Are == and != mutually dependent?

I'm learning about operator overloading in C++, and I see that == and != are simply some special functions which can be customized for user-defined types. My concern is, though, why are there two separate definitions needed? I thought that if a == b is true, then a != b is automatically false, and vice versa, and there is no other possibility, because, by definition, a != b is !(a == b) .

是==和!=相互依赖吗?

我学习了C ++中的运算符重载,并且我发现==和!=只是一些可以为用户定义的类型定制的特殊函数。 不过,我担心为什么需要两个单独的定义? 我认为如果a == b是真的,那么a != b自动为false,反之亦然,并且没有其他可能性,因为根据定义, a != b是!(a == b) 。 而我无法想象任何情况都不是这样。 但是也许我的想象力有限,或者我对某些东西一无所知? 我知道我可以用另一个来定义一个,但这不是我所问的。 我也没有问及按

Matches overlapping lookahead on LZ77/LZSS with suffix trees

As I understand it, given a suffix tree, we are interested (roughly) in computing, for each suffix S, which longer suffix has the longest common prefix with S. Add a reference from each tree node to the descendant leaf with the longest suffix (linear time with DFS). From each leaf, walk rootward, examining the new references, stopping if a longer suffix is found. The running time of the latte

在LZ77 / LZSS上与后缀树匹配重叠前瞻

据我了解,给定一个后缀树,我们感兴趣(粗略地)计算中,对于每个后缀S,​​较长的后缀与S最长的公共前缀。 将每个树节点的引用添加到后缀最长的后代叶(使用DFS的线性时间)。 从每片叶子,向根部走,检查新的参考,如果找到更长的后缀则停止。 后一步的运行时间是线性的,因为每个树边缘只被检查一次。 不幸的是,一个有界窗口的生活更加困难。 我们传播了几个,而不是传播一个参考。 为了计算从一个节点引用的一组后