copy-constructor Questions
4
Solved
Why is the copy constructor called when returning from bar instead of the move constructor?
#include <iostream>
using namespace std;
class Alpha {
public:
Alpha() { cout << "ctor" &...
Ceria asked 22/8, 2017 at 2:9
4
Solved
I have trouble understanding the sentence with respect to inline and customers binary compatibility. Can someone please explain?
C++ FAQ Cline, Lomow:
When the compiler synthesizes the copy con...
Cate asked 16/8, 2017 at 20:23
2
Solved
I have a class A with lots of data members, some of which are constant. All data members have proper copy constructors, so I want to default a copy constructor of my class:
class A
{
public:
A() ...
Awfully asked 1/8, 2017 at 8:38
3
Solved
I wrote a class with a constexpr copy constructor. (It is a struct in example to make it simpler.) One of the fields is an array. I want copy it too.
struct Foo
{
static constexpr int SIZE = 4;
...
Taneka asked 22/11, 2014 at 23:29
6
Solved
I'm a little confused as to the mechanics of the copy constructor. Correct me if I'm wrong:
If a method takes a reference to an object as a parameter, and the class defines a copy construtor, the...
Vietnam asked 6/2, 2010 at 17:11
2
Solved
If I understood correctly, starting from C++17, this code now requires that no copy will be done:
Foo myfunc(void) {
return Foo();
}
auto foo = myfunc(); // no copy
Is it also true for functio...
Pekan asked 29/5, 2017 at 16:7
4
Consider the below code:
#include<iostream>
using namespace std;
class A
{
public:
A() {cout << "1";}
A(const A &obj) {cout << "2";}
};
class B: virtual A
{
public:
B() {...
Camden asked 30/4, 2017 at 5:28
3
Supose I have a class containing many fields, and/or is constantly changing (in development), and all its fields are either natives or of not-necessarily-POD types which provide a satisfactory copy...
Vasquez asked 30/11, 2015 at 21:58
5
Solved
I frequently run into the problem, that I must extend a compiler generated copy constructor. Example:
class xyz;
class C
{
...
int a, b, c;
std::set<int> mySet;
xyz *some_private_ptr;
}...
Inrush asked 31/1, 2011 at 16:51
2
Solved
#include <iostream>
#include <string>
#include <array>
class C {
private:
std::string a;
std::string b;
std::string c;
public:
C(std::string a_, std::string b_, std::string c...
Marino asked 9/2, 2017 at 16:36
2
Solved
We have the following method to test if our structure is a POD or not. It always returns true:
bool podTest() {
struct podTest {
int count;
int x[];
};
return std::is_pod<podTest>::val...
Whitewood asked 6/2, 2017 at 23:1
2
Solved
Suppose I have a weird string type, that either owns or doesn't own it's underlying buffer:
class WeirdString {
private:
char* buffer;
size_t length;
size_t capacity;
bool owns;
public:
// N...
Munich asked 23/1, 2017 at 22:47
2
Solved
Based on this code
struct Foo
{
Foo()
{
cout << "default ctor" << endl;
}
Foo(std::initializer_list<Foo> ilist)
{
cout << "initializer list" << endl;
}
...
Mixologist asked 8/2, 2016 at 15:18
7
Solved
I've created a simple test case exhibiting a strange behavior I've noticed in a larger code base I'm working on. This test case is below. I'm relying on the STL Map's "[ ]" operator to create a poi...
Tko asked 25/10, 2010 at 19:2
1
Consider the following program:
#include <iostream>
struct X {
X () = default;
X (X &) { std::cout << "non-const called" << std::endl; }
X (X const &) { std::cout <...
Bronchiectasis asked 3/12, 2016 at 16:57
8
Solved
I have a long class with a lot of data members. I want to write a copy constructor for it. But, if I write my own copy constructor, I lose access to the default copy constructor.
I just want to rep...
Coxcombry asked 14/9, 2012 at 10:52
2
Solved
I want to assign one class object to another class object in c++.
Ex:
There is one class Dog and another class Cat. Create one one instance of each (d1 & c1). Don't want to use any STL. I want...
Risibility asked 17/9, 2016 at 15:39
2
Solved
I'm writing a class where I have a templated constructor and copy constructor. Every time I want to call copy constructor with non const object, templated constructor gets chosen. How can I force c...
Headmost asked 10/9, 2016 at 8:51
3
Can anyone explain the meaning of *p=*q in this C++ code? Is this a copy constructor concept?
class A{
//any code
}
int main(){
A *p=new A();
A *q=new A();
*p=*q;
return 0;
}
Belga asked 4/9, 2016 at 13:6
9
Solved
Why doesn't Java support a copy constructor like in C++?
Inert asked 6/5, 2009 at 2:34
4
Solved
In book C++ Primer 13.5.1, it implement a Smart Pointer Class using a Use-Count Class. Their implementation is as follows:
Use-Count Class
// private class for use by HasPtr only
class U_Ptr {
...
Whichsoever asked 3/1, 2014 at 4:34
3
I have a rather large and lengthy class where the implicitly generated copy-constructor would almost do exactly the right thing, except for one specific field.
Is there a way to write a user-defin...
Inarch asked 22/8, 2016 at 21:50
1
Solved
In the following code, "situation 1" works as expected on all
compilers tested, however "situation 2" it seems to behave differently
based on the compiler used.
As an example MSVC has sit1 and sit...
Husted asked 16/8, 2016 at 22:16
5
Solved
Let's say I have a class with multiple constructors, one of which is a copy-constructor (to copy an object):
public class Rectangle {
int width, height;
public Rectangle(int width, int height)...
And asked 29/7, 2016 at 9:42
6
Solved
Why is the argument of the copy constructor a reference rather than a pointer?
Why can't we use the pointer instead?
Visional asked 4/9, 2013 at 10:34
© 2022 - 2024 — McMap. All rights reserved.