copy-constructor Questions
3
I have a class at type script:
export class Child {
name:string;
age:number;
}
I want to force class instances to have only properties that class declaration has.
For example, if I get from f...
Related asked 10/11, 2016 at 6:45
1
Solved
What is the feature that allows me use auto for non-copyable (and non-movable) types in C++17 and didn't for C++14?
Consider the following code:
struct A{
A(A const&)=delete;
A(A&&)...
Within asked 20/10, 2019 at 3:22
2
Solved
Why compiler cares about copy constructor when it doesn't need one?
#include <iostream>
template<typename T>
void print(T);
class Foo {
Foo(const Foo&);
public:
Foo(){}
};
te...
Ewer asked 30/9, 2019 at 16:37
8
Solved
I was going through Copy Constructors, I have gone through the links in stack over flow and others as well. But i am not clear on the following points.
Why do we need a Copy Constructor
When do w...
Nonplus asked 31/3, 2015 at 6:39
2
Solved
Assume I have this function
void foo() noexcept
{
// Safely noexcept code.
}
And then this class:
class Bar
{
Bar(const Bar&) { ... } // Is not noexcept, so might throw
// Non mova...
Bewhiskered asked 20/9, 2019 at 15:50
3
Solved
#include <iostream>
struct uct
{
uct() { std::cerr << "default" << std::endl; }
uct(const uct &) { std::cerr << "copy" << std::endl; }
uct( uct&&) { s...
Deviate asked 12/9, 2019 at 15:23
3
Solved
Under certain conditions, I'd like to SFINAE away the copy constructor and copy assignment operator of a class template. But if I do so, a default copy constructor and a default assignment operator...
Farber asked 3/4, 2015 at 10:7
5
Solved
There is a class in our code, say class C. I want to create a vector of objects of class C. However, both the copy constructor and assignment operator are purposely declared to be private. I don't ...
Casseycassi asked 11/5, 2011 at 4:4
4
Solved
I have a Base class
class Keyframebase
{
private:
std::string stdstrName;
float time;
KeyframeType keyframeType;
public:
Keyframebase();
Keyframebase(KeyframeType keyType);
Keyframebase(const...
Reena asked 24/7, 2019 at 6:41
3
Solved
Here's the definition of copy constructor, [class.copy.ctor/1]:
A non-template constructor for class X is a copy constructor if its first parameter is of type X&, const X&, volatile X&am...
Catron asked 25/4, 2019 at 9:22
2
Disclaimer: Goal of research is how to disable copy elision and return value optimization for supplied part of code. Please avoid from answering if want to mention something like XY-problem. The qu...
Playreader asked 3/4, 2019 at 8:25
2
Solved
I'm playing around with a few things to understand how copy constructors work. But I can't make sense of why the copy constructor is called twice for the creation of x2. I would have assumed it wou...
Rumal asked 28/2, 2019 at 15:37
2
Solved
Assuming there is no compiler optimization. How many times would OutputBuffer_s type object will be created?
#include <iostream>
#include <vector>
struct OutputBuffer_s {
int encoded...
Variegate asked 27/2, 2019 at 9:2
5
Solved
I have a hurdle with noexcept specifier next to my copy constructor.
#include <memory>
#include <vector>
class Foo final {
public:
Foo() noexcept = default;
Foo(const Foo& oth)...
Phospholipide asked 25/1, 2019 at 8:9
3
Solved
I have heard that C++ has something called "conversion constructors" or "converting constructors". What are these, and what are they for? I saw it mentioned with regards to this code:
class MyClas...
Vickivickie asked 25/2, 2013 at 22:9
2
Consider the following C++ code with my failed attempt to avoid preference of non-template copy&move constructors and assignment operators:
template<typename T> class A {
public:
A() { ...
Freeload asked 5/1, 2019 at 10:2
7
Solved
I know that C++ compiler creates a copy constructor for a class. In which case do we have to write a user-defined copy constructor? Can you give some examples?
Nolita asked 19/7, 2010 at 5:21
1
Solved
I deleted a copy constructor in base class but I can't get if the compiler will create an implicit copy constructor in child classes? Or does a deleted constructor in the base class prevent it?
te...
Barnie asked 12/12, 2018 at 12:54
2
Solved
This is something I have wondered for a long time. Take the following example:
struct matrix
{
float data[16];
};
I know what the default constructor and destructor do in this specific example ...
Quip asked 12/11, 2010 at 11:50
3
Solved
If we have a container with non-copyable value type, such a container class still defines the copy constructor, just it may not be invoked.
using T = std::vector<std::unique_ptr<int>>;...
Implicative asked 8/11, 2018 at 14:51
3
Solved
Can a derived class be made uncopyable by declaring copy constructor/operator private in base class?
I thought in theory the answer to this question was yes.
However, in practice, my compiler (VS2010) does not seem to complain in the following situation: I have an abstract base class providing so...
Scraper asked 8/7, 2015 at 9:57
2
I am attempting to delete the copy constructor using the c++ type system to prevent copying an object.
struct DeleteCopyConstructor {
DeleteCopyConstructor() {};
DeleteCopyConstructor(DeleteCopy...
Tomchay asked 25/6, 2017 at 20:56
1
Solved
Today I encountered something I don't really understand about copy constructor.
Consider the next code:
#include <iostream>
using namespace std;
class some_class {
public:
some_cl...
Hemihedral asked 21/9, 2018 at 14:59
1
Solved
I have a class ModelRecorder with contains a reference modelRef_ to another class OpModel.
class ModelRecorder : public CompositionalModel //This is an abstract base class
{
OpModel& modelRe...
Vizor asked 23/8, 2018 at 10:6
10
Solved
See title.
I have:
class Foo {
private:
Foo();
public:
static Foo* create();
}
What need I do from here to make Foo un-copyable?
Other asked 31/1, 2010 at 22:59
© 2022 - 2024 — McMap. All rights reserved.