copy-constructor Questions

2

I have long being confused with whether Java's container's copy constructor is shallow copy or deep copy? Below is my understanding: ints1, ints2, ints3 are references so they lie in stack. inst1 p...
Rausch asked 18/12, 2017 at 5:39

1

Solved

#include<iostream> using namespace std; class A { public: A(){ cout <<"1";} A(const A &obj){cout <<"2";} }; class B: virtual A { public: B(){cout <<"3";} B(const B ...

3

Solved

Consider the following code: #include <memory> #include <vector> class A { private: std::vector<std::unique_ptr<int>> _vals; }; int main() { A a; //A a2(a); return 0;...

2

Solved

In c++98, the following program is expected to call the copy constructor. #include <iostream> using namespace std; class A { public: A() { cout << "default" ; } A(int i) { cout &l...
Ramose asked 13/6, 2018 at 9:50

1

Simplified code: #include <queue> #include <memory> #include <vector> class Foo { public: Foo() {}; virtual ~Foo() {} }; int main() { std::queue<std::unique_ptr<Foo&gt...
Mastitis asked 5/6, 2018 at 1:10

1

Solved

I am having trouble writing this fairly simple program. I have two class A and B. B has an object of A. I need to write Copy constructor of B so that two instances of B will have the different inst...
Larkin asked 23/5, 2018 at 3:2

2

I have a class with both a copy constructor and a constructor taking a std::reference_wrapper: #include <functional> #include <iostream> class Class { public: Class() { std::cout &l...
Tabb asked 2/5, 2018 at 14:32

2

Solved

Let's have this code: Test1 t1; Test2 t2; t1 = t2; I believe there are three (or more?) ways how to implement t1 = t2 to overload assign operator in Test1 to overload type cast operator in Tes...
Tabloid asked 9/9, 2012 at 0:54

2

Solved

I have a class called classA, something like this: class classA { private: char* data; public: classA(const classA&) = delete; ~classA(); }; ~classA() { delete[] data; } In anot...
Fourierism asked 12/4, 2018 at 23:29

1

Solved

Consider the following program: #include <iostream> #include <utility> class T { public: T() { printf("address at construction: %zx\n", (uintptr_t)this); } // T(const T&) { prin...

1

Solved

I wonder why this program doesn't compile (the same behavior on msvc, gcc and clang): #include <iostream> using namespace std; struct Action { virtual void action() { cout << "Act...
Greasy asked 8/3, 2018 at 12:56

1

I want to inherit copy constructor of the base class using using keyword: #include <iostream> struct A { A() = default; A(const A &) { std::cerr << __PRETTY_FUNCTION__ <<...
Estrous asked 1/3, 2018 at 7:55

2

I have the following (admittedly contrived) code that compiles just fine in gcc 6, but doesn't compile in gcc 7. Notice the use of an undeclared constructor in the definition of bar. This should pr...
Lipfert asked 25/2, 2018 at 3:0

3

Solved

The compiler generates some class methods like copy constructors, destructors, etc. Is it possible to have gdb break on those methods to, e.g., observe where objects are being copied or destroyed? ...
Singleaction asked 3/4, 2014 at 19:36

1

Solved

Consider the following minimal working example: #include <atomic> int main() { ::std::atomic<bool> a = false; } Copy ctor and copy assignment of atomic are both explicitly deleted....
Rosarosabel asked 20/2, 2018 at 10:33

8

Solved

I understand that when we define a class copy constructor of the class is necessary as Rule of three states. I also notice that the argument of the copy constructor is usually const as the followin...
Actinism asked 6/6, 2013 at 7:59

7

Solved

public class SuperCar: Car { public bool SuperWheels { get {return true; } } } public class Car { public bool HasSteeringWheel { get {return true;} } } How can I set the base class for the de...
Worst asked 28/1, 2011 at 1:4

4

Solved

Suppose I have a POD type like this: struct A { char a; int b; }; On my system, sizeof(A) == 8, even though sizeof(char) == 1 and sizeof(b) == 4. This means that the data structure has 3 unuse...
Cotquean asked 22/10, 2017 at 14:10

1

Solved

Why this: struct A { A(int) { cout << "construct from int" << endl; } A(A&&) = delete; A(const A &) { cout << "copy constructor" << endl; } }; int mai...
Bilge asked 14/10, 2017 at 22:6

2

I'm on Visual Studio 2017. Recently, because I didn't like the non-conforming standards to C++ I went ahead and disabled the non-standard language extensions in the options. So far so good. Now I h...
Concatenate asked 14/10, 2017 at 11:15

1

Solved

I could not find where in the standard it is stated that it is forbidden to explicitly default a copy-constructor and copy-assignment with a volatile& or const volatile& argument, like this...
Tyronetyrosinase asked 4/10, 2017 at 7:29

1

Solved

I have a class that holds a std::vector like struct Mystruct { Mystruct(const std::vector<int>& w): v(w) { std::cout << "Copy constructor :" << v.at(0) << "\n"; }...
Cesya asked 1/10, 2017 at 14:44

3

Solved

I am wondering why in the following C++ code the copy constructor is called 25 times for 10 iterations? If it was 10 then OK 10/10 = 1, or 20/10 = 2, or 30/10 = 3, but 25/10 = 2.5? What doe...
Squadron asked 21/9, 2017 at 9:59

3

Solved

Here is an extract from item 56 of the book "C++ Gotchas": It's not uncommon to see a simple initialization of a Y object written any of three different ways, as if they were equivalent. Y ...
Snapp asked 17/3, 2010 at 14:0

2

Solved

Consider the following code: #include <iostream> #include <vector> using namespace std; class A { public: A(int) { cout << "int" << endl; } A(A&&) { cout &...

© 2022 - 2024 — McMap. All rights reserved.