Answer the question
In order to leave comments, you need to log in
What is the order in which a new object is assigned?
Hello, I want to understand this:
Type a;
Type b = a; //Тут вызывается operator= или конструктор копирования?
Type& Type::operator=(const Type&);
Type b = Type(a);
Type b = (operator=(&(Type(&a))))//Абстракция, не сочтите за ошибку
Answer the question
In order to leave comments, you need to log in
#include <iostream>
class A
{
public:
A()
{
c = counter++;
};
int c;
private:
static int counter;
};
int A::counter =0;
int main (int argc, char ** argv)
{
A a1;
A a2;
A a3;
std::cout << a1.c << a2.c << a3.c << std::endl;
std::cout << (a2 = a1).c <<std::endl;
std::cout << a1.c << a2.c << a3.c << std::endl;
a2.c = 1;
std::cout << a1.c << a2.c << a3.c << std::endl;
return 0;
}
And this means that by manipulating the members of b I will edit the memory of a?
class C
{
public:
C() {}
C (const C&) { std::cout << "Copy ctor" << std::endl; }
C & operator = (const C&) { std::cout << "Assign" << std::endl; return *this; }
};
int main()
{
C a;
C b = a;
Type b;
b = a;
int a = 10;
C b = C(a);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question