rule-of-three


C++ Copy Constructor + Pointer Object

荒凉一梦 提交于 2020-01-09 21:36:22
问题 I'm trying to learn "big three" in C++.. I managed to do very simple program for "big three".. but I'm not sure how to use the object pointer.. The following is my first attempt. I have a doubt when I was writing this... Questions Is this the correct way to implement the default constructor? I'm not sure whether I need to have it or not. But what I found in another thread about copy constructor with pointer is that I need to allocate the space for that pointer before copying the address in

C++ Copy Constructor + Pointer Object

北城以北 提交于 2020-01-09 21:30:10
问题 I'm trying to learn "big three" in C++.. I managed to do very simple program for "big three".. but I'm not sure how to use the object pointer.. The following is my first attempt. I have a doubt when I was writing this... Questions Is this the correct way to implement the default constructor? I'm not sure whether I need to have it or not. But what I found in another thread about copy constructor with pointer is that I need to allocate the space for that pointer before copying the address in

C++ Copy Constructor + Pointer Object

限于喜欢 提交于 2020-01-09 21:29:28
问题 I'm trying to learn "big three" in C++.. I managed to do very simple program for "big three".. but I'm not sure how to use the object pointer.. The following is my first attempt. I have a doubt when I was writing this... Questions Is this the correct way to implement the default constructor? I'm not sure whether I need to have it or not. But what I found in another thread about copy constructor with pointer is that I need to allocate the space for that pointer before copying the address in

Exception to the Rule of Three?

╄→гoц情女王★ 提交于 2019-12-30 02:48:12
问题 I've read a lot about the C++ Rule of Three. Many people swear by it. But when the rule is stated, it almost always includes a word like "usually," "likely," or "probably," indicating that there are exceptions. I haven't seen much discussion of what these exceptional cases might be -- cases where the Rule of Three does not hold, or at least where adhering to it doesn't offer any advantage. My question is whether my situation is a legitimate exception to the Rule of Three. I believe that in

Default constructor missing - but I'm not calling it?

拈花ヽ惹草 提交于 2019-12-29 09:21:53
问题 I'm writing a C++ application in which I have a Controller class with two nested structs, defined in my header file as follows: class Controller { struct help_message { // controller.hpp, line 19 std::string summary; std::string details; help_message(const std::string&, const std::string&); }; struct player_command { cmd_t cmd; help_message help; // cmd_t is my own typedef, irrelevant for this question player_command(const cmd_t&, const help_message&); }; // more members... }; In my source

Must a c++ interface obey the rule of five?

China☆狼群 提交于 2019-12-21 03:33:42
问题 What is the correct way to declare instantiation methods when defining an interface class? Abstract base classes are required to have a virtual destructor for obvious reasons. However, the following compilation warning is then given: "'InterfaceClass' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator", which is the 'rule of five'. I understand why the 'rule of five' should be obeyed in general,

What's with the copy-constructor if the class contains a user-declared destructor?

為{幸葍}努か 提交于 2019-12-12 10:48:33
问题 The Standard in section 12.8/7 says: If the class definition does not explicitly declare a copy constructor, one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted; otherwise, it is defined as defaulted (8.4). The latter case is deprecated if the class has a user-declared copy assignment operator or a user-declared destructor . Thus, for the class definition struct X { X(const

Rule of Three in C++

一个人想着一个人 提交于 2019-12-12 01:57:18
问题 I've read that The Rule of Three, What is The Rule of Three? is summarized as follows: If you need to explicitly declare either the destructor, copy constructor or copy assignment operator yourself, you probably need to explicitly declare all three of them. My question is: In a C++ application, I have a class that manages resources (has a destructor that handles deleting pointers). I know that the application uses assignment operator all over the place, but I am absolutely certain that there

Are there any static analysis tools that check for Rule of 3 (or Rule of 5 C++11)

瘦欲@ 提交于 2019-12-10 06:16:59
问题 I am currently working on a codebase that is built on a foundation of sand. There are numerous classes in supposedly tested libraries that violate the "Rule of 3". Most declare a non-trivial destructor, but are missing either a copy constructor or assignment operator. Are there any compiler flags (gcc) or static analysis tools that warn when a class violates the rule of 3? Currently we are using Coverity with GCC version 4.4. 回答1: Coverity has. We use version 6.5. There is a checker MISSING

Are there any static analysis tools that check for Rule of 3 (or Rule of 5 C++11)

妖精的绣舞 提交于 2019-12-05 16:07:30
I am currently working on a codebase that is built on a foundation of sand. There are numerous classes in supposedly tested libraries that violate the "Rule of 3". Most declare a non-trivial destructor, but are missing either a copy constructor or assignment operator. Are there any compiler flags (gcc) or static analysis tools that warn when a class violates the rule of 3? Currently we are using Coverity with GCC version 4.4. Coverity has. We use version 6.5. There is a checker MISSING_COPY_OR_ASSIGN. C++test from Parasoft (commercial tool) has a rule (MRM-40) that covers "copy and destroy

工具导航Map