Initializes an object from another object
Questions tagged [copy-initialization]
52 questions
0
votes
1 answer
Copy constructor implicit conversion problem
Part of the answer is given in here
class foo1
{
private:
int i;
public:
foo1()
{
i=2;
}
int geti(){
return i;
}
};
class foo2
{
private:
int j;
public:
…

anurag86
- 1,635
- 1
- 16
- 31
0
votes
0 answers
Why initializing an object of a value whose type there's a defined ctor doesn't invoke the copy constructor?
Hello I have a simple question: If I have a class that has a constructor that takes an integer for example then if I copy-initialize an object of that class then is copy-constructor or constructor is called:
class M
{
public:
M(int) {…

Maestro
- 2,512
- 9
- 24
0
votes
1 answer
Use of the chain method in the continuation of the copy constructor/initialization in one declaration statements in c++?
As you know, we usually use the return by reference for the method chaining, I use the return by reference in the first code and the output is as I have predicted. In the second code block, when I did not use the return by reference, the chain was…
0
votes
1 answer
Relaxation of copy initialization requirements in C++17
I'm confused by the cppref statements:
[...] The result of the conversion, which is a prvalue expression (since
C++17) if a converting constructor was used, is then used to
direct-initialize the object.
The last step is usually optimized out…

Lingxi
- 14,579
- 2
- 37
- 93
0
votes
2 answers
Copy constructor/Assignment operator confusion when initializing object
What's the difference between doing this:
class_name object_name = something;
and
class_name object_name(something);
From what I read here, both use the copy constructor but I don't understand why that happens and how implicit conversions come…

Veritas
- 2,150
- 3
- 16
- 40
0
votes
1 answer
direct initialization of a POD variable does not work but copy initialization does when pushing the variable onto a vector
Why does the following code fail to compile, while the two examples after compile successfully? I'm using VS 2008 on Windows 7.
Direct initialization of POD (fails):
int pod();
std::vector pods;
//pods.push_back(pod); // This will generate a…

Chris Morris
- 4,335
- 4
- 24
- 28
-1
votes
1 answer
Why copy-list-initialization and copy-initialization behave differently for this case?
#include
#include
class testClass {
public:
// testClass(const char * s)
// {
// std::cout<<"custom constructor 1 called"<

Wubin Ouyang
- 777
- 1
- 7
- 9