copy-constructor Questions
2
Solved
Using Clang 3.7 on windows platform
See following code:
class A1
{
public:
A1(char* name){}
virtual ~A1() {}
private:
A1(const A1&) {}
};
class B1 : public A1
{
public:
B1(): A1(""){}
};...
Oestriol asked 23/6, 2016 at 10:4
7
Solved
I have a class that contains a dynamically allocated array, say
class A
{
int* myArray;
A()
{
myArray = 0;
}
A(int size)
{
myArray = new int[size];
}
~A()
{
// Note that as per MikeB's...
Audette asked 1/11, 2008 at 7:15
3
Solved
I have 2 classes, A and B. In A I have 3 private fields. In class B I would like to write a copy constructor, and initialize private fields from class A. However, this does not work:
#include <...
Boyse asked 7/4, 2016 at 17:6
1
Solved
It's possible to make a local copy of an iostream object, using rdbuf and copyfmt. This allows formatting changes to be locally scoped:
std::ostream & operator << ( std::ostream & os...
Nuisance asked 17/3, 2016 at 4:26
2
Solved
snippet 1:
#include<iostream>
using namespace std;
class C{
public:
C(){}
C(const C& c){
cout<<"const copy constructor called"<<endl;
}
};
int main(){
C c1;
C c2 = c1;...
Neumark asked 22/2, 2016 at 5:26
4
Solved
I have a template 'Foo', which owns a T, and I'd like it to have a variadic constructor that forwards its arguments to T's constructor:
template<typename T>
struct Foo {
Foo()
: t() {}
...
Widner asked 18/12, 2012 at 16:58
3
Solved
I realize questions quite similar to this have been asked, though not exactly this way.
I'd like to have an optional argument for the constructor of my class that, if it is an instance of my class...
Imparisyllabic asked 17/5, 2012 at 17:36
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
5
Solved
From the boost library documentation I read this:
Conceptually, smart pointers are seen as owning the object pointed to,
and thus responsible for deletion of the object when it is no longer
ne...
Constraint asked 17/12, 2012 at 10:26
1
Solved
This question refers only to pre C++11. Consider the following seemingly broken code:
struct X
{
X(){} // default user-provided constructor
private:
X(const X&){}
};
int main()
{
X x = X()...
Penal asked 5/1, 2016 at 1:44
1
Solved
I have the following code snippet.
#include <iostream>
#include <functional>
using namespace std;
struct A
{
A() { cout << "A "; data = 1; }
A(const A& a) { cout << ...
Polygnotus asked 1/12, 2015 at 13:11
2
Solved
I have a use case that my object must not be copied in any way. I have written an exaggerated complete list of copy constructor and copy assignment operator deletions below. There are so many of th...
Stavanger asked 18/11, 2015 at 9:51
2
Solved
I was reading Why would a copy constructor have more than one parameter?.
The accepted answer says that:
The old std::basic_string does have one too:
basic_string(const basic_string& s,
si...
Muggins asked 6/10, 2015 at 18:20
3
Solved
I am trying to use the constructor inheritance feature of C++11. The following snippet (copied from somewhere, I don't remember whence) works completely fine:
#include <iostream>
struct Bas...
Deafanddumb asked 5/10, 2015 at 17:46
2
Solved
Consider the following program:
#include <iostream>
struct Test
{
int a;
Test() : a(3)
{ }
Test(const Test& t...)
{
std::cout<<"Copy constructor called\n";
a=t.a;
}
int ge...
Joannajoanne asked 1/10, 2015 at 18:9
3
Solved
I have a template class that has a template copy constructor. The problem is when I instantiate this class using another instance of this class with the same template type, my template copy constru...
Kummerbund asked 12/9, 2015 at 10:55
2
Solved
I've found strange behavior of a code which is apparently ignoring const-ness:
#include <iostream>
using std::cerr;
class A
{
public:
A() { cerr << "A::A()\n"; }
A(const A &a) ...
Lumpish asked 3/9, 2015 at 8:18
1
Solved
Explicit copy constructors disallow something like Foo foo = bar;, and enforce the copy usage as Foo foo(bar);. In addition, explicit copy constructors also disallow returning objects by value from...
Congenital asked 2/8, 2015 at 20:39
7
Solved
I used to think C++'s object model is very robust when best practices are followed.
Just a few minutes ago, though, I had a realization that I hadn't had before.
Consider this code:
class Foo
{
st...
Leniency asked 7/6, 2015 at 0:23
3
I've got a class A (from a library over which I have no control) with a private copy constructor and a clone method, and a class B derived from A. I would like to implement clone for B as well.
Th...
Corking asked 5/6, 2015 at 11:19
2
Solved
I have a class (C) with a vector of unique_ptrs to an abstract class (A) as a member. This is because C must work with all classes of type A, i.e. its children.
The problem is that I cannot figur...
Leis asked 3/6, 2015 at 22:22
1
Solved
Me and a colleague of mine had a debate about wether
Pt pt;
and
Pt pt = Pt();
are equivalent. I suspected that in the second case copy assignment could be called, but as it turns out...
Knavish asked 13/5, 2015 at 10:7
2
Solved
Let's say you have an object of type T and a suitably-aligned memory buffer alignas(T) unsigned char[sizeof(T)]. If you use std::memcpy to copy from the object of type T to the unsigned char arra...
Heterothallic asked 3/10, 2014 at 0:53
2
Solved
After trying to write an example regarding move constructors, I ran into the following code:
#include <utility>
#include <iostream>
using namespace std;
class Data
{
public:
Data()
...
Assignable asked 20/4, 2015 at 12:9
4
Solved
I need help with the non-copyable nature of [io](f)streams.
I need to provide a hackish wrapper around fstreams in order to handle files with unicode characters in their filenames on Windows. For ...
Conjoined asked 29/6, 2011 at 17:31
© 2022 - 2024 — McMap. All rights reserved.