rule-of-three Questions

4

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 followi...
Protector asked 22/4, 2018 at 1:49

3

Solved

Consider the following program: #include <string> struct S { S (){} private: void *ptr = nullptr; std::string str = ""; }; int main(){} This, when compiled with -Weffc++ on GCC 4.7.1...
Lunik asked 16/7, 2012 at 0:50

9

Solved

So, after watching this wonderful lecture on rvalue references, I thought that every class would benefit of such a "move constructor", template<class T> MyClass(T&& other) edit ...
Allyn asked 24/1, 2011 at 13:51

5

Solved

The rule of 5 states that if a class has a user-declared destructor, copy constructor, copy assignment constructor, move constructor, or move assignment constructor, then it must have the other 4. ...
Interferometer asked 26/12, 2020 at 10:29

1

In the following example we have a class Class that contains a Bridge object that takes care of all the memory handling for us (rule of three). class Base { public: Base() {}; virtual Base* clone...
Usurp asked 25/9, 2020 at 7:56

1

Solved

For my understanding, the rule of five is a guidelince rule. Altough, I've seen that the compiler in some scenarios may delete functions, implicitly. For example, when defining a move-ctor', ...
Fortunato asked 25/9, 2017 at 10:27

2

Solved

While reading the Bjarne Stroustrup's CoreCppGuidelines, I have found a guideline which contradicts my experience. The C.21 requires the following: If you define or =delete any default operatio...
Ushijima asked 31/7, 2016 at 9:41

8

Solved

What does copying an object mean? What are the copy constructor and the copy assignment operator? When do I need to declare them myself? How can I prevent my objects from being copied?
Tenebrific asked 13/11, 2010 at 13:27

2

Solved

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 ...
Darien asked 1/11, 2014 at 8:23

2

Solved

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-trivia...
Mythify asked 7/5, 2013 at 15:57

3

Solved

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 ar...
Selfish asked 21/3, 2013 at 20:27

3

Solved

I'm learning c++ and I recently learned (here in stack overflow) about the copy-and-swap idiom and I have a few questions about it. So, suppose I have the following class using a copy-and-swa...
Sentience asked 6/5, 2011 at 0:25

5

Solved

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 w...
Adventitia asked 18/9, 2010 at 5:7

3

Solved

What is "minimal framework" (necessary methods) of complex object (with explicitly malloced internal data), which I want to store in STL container, e.g. <vector>? For my assumptions (example...
Rarefy asked 23/3, 2010 at 15:30
1

© 2022 - 2024 — McMap. All rights reserved.