copy-initialization Questions
2
Solved
I recently learnt that we can have more than one default constructor in a class. Then I wrote the following program that compiles with msvc but both clang and gcc fails to compile this.
struct A
{
...
Stereotypy asked 9/1 at 18:4
2
The following code compiles with MSVC (/permissive-) and fails to compile with GCC/Clang for m_ptr1 and m_ptr2.
#include <memory>
struct ForwardDeclared;
class A {
public:
explicit A();
...
Continuative asked 14/12, 2020 at 9:23
1
Solved
In the next program, struct B with deleted copy-constructor is thrown and caught by value:
struct B {
B() = default;
B(const B&) = delete;
};
int main() {
try {
throw B{};
}
catch( B ) {...
Selfevident asked 2/11, 2021 at 8:9
2
Solved
In this example, is it possible to allow the deduction of the template parameters type of the tuple?
#include<tuple>
#include<string>
template<class T1, class T2>
void fun(std::...
Timbering asked 23/5, 2013 at 0:39
9
Solved
Suppose I have this function:
void my_test()
{
A a1 = A_factory_func();
A a2(A_factory_func());
double b1 = 0.5;
double b2(0.5);
A c1;
A c2 = A();
A c3(A());
}
In each grouping, are the...
Vitellin asked 26/6, 2009 at 21:36
1
Solved
I have the following code:
#include <string_view>
class Foo
{
public:
Foo(std::string_view) {}
};
When I do this, everything compiles fine (using clang v8, C++17):
Foo f("testing");
H...
Linnet asked 24/7, 2019 at 16:0
2
Solved
My question is different because I may "know" copy-elision. I am learning copy initialization. However,the following code confused me because I have already turned off the copy-elision using -fno-e...
Ideology asked 10/7, 2018 at 5:34
2
Solved
I would like to know how I should define the class my_int so that the cast from int to std::complex< my_int > is done by the compiler instead of manually by me.
The following program does no...
Creed asked 14/5, 2018 at 10:26
1
Solved
I have some code like the following:
class bar;
class foo
{
public:
operator bar() const;
};
class bar
{
public:
bar(const foo& foo);
};
void baz() {
foo f;
bar b = f; // [1]
const fo...
Dichromate asked 11/8, 2017 at 13:29
2
Solved
Given the following:
#include <stdio.h>
class X;
class Y
{
public:
Y() { printf(" 1\n"); } // 1
// operator X(); // 2
};
class X
{
public:
X(int) {}
X(const Y& rhs) { printf(" 3\n...
Marnimarnia asked 1/6, 2017 at 11:43
1
Solved
#include <iostream>
using namespace std;
struct CL2
{
CL2(){}
CL2(const CL2&){}
};
CL2 cl2;
struct CL1
{
CL1(){}
operator CL2&(){cout<<"operator CL2&"; return cl2;}
...
Spectral asked 6/12, 2015 at 16:35
1
Solved
Before C++11, we can do copy initialization by writing something like A a = 1; which is more or less equivalent to A a = A(1);. That is, a temporary is first created and then a copy ctor is invoked...
Remissible asked 17/11, 2014 at 1:35
1
Solved
In the following code I am not allowed to declare an explicit ctor because the compiler says I am using it in a copy-initializing context (clang 3.3 and gcc 4.8).
I try to prove the compilers wrong...
Weakly asked 13/12, 2013 at 5:18
1
Solved
Possible Duplicate:
What’s the motivation behind having copy and direct initialization behave differently?
And by copy initialization, I mean like so:
struct MyStruct
{
MyStruct(int...
Burch asked 4/12, 2012 at 4:18
6
Solved
I was reading the difference between direct-initialization and copy-initialization (§8.5/12):
T x(a); //direct-initialization
T y = a; //copy-initialization
What I understand from reading about ...
Sheaff asked 28/5, 2011 at 16:56
3
Solved
Given the following code:
class temp
{
public:
string str;
int num;
};
int main()
{
temp temp1;
temp temp2 = temp();
cout << temp1.str << endl; //Print ""
cout <<...
Sayed asked 14/5, 2011 at 2:55
2
Is it simply preference or are there specific instances where one is necessary over another? I'm refering to the following variants for initialization
T t(e); // direct initialization
T t = e; // ...
Jinnyjinrikisha asked 27/11, 2010 at 19:59
1
© 2022 - 2024 — McMap. All rights reserved.