what the`()` `{}` mean in the member initializer lists?what’s wrong with my code that the output is not`1121`but`1222`?

  c++

in my oppinion,p{n}stand for this.p=n and n(a) means this.n=this.a,is it right?
i already define a costruction like task1(int a,int n):a{a},n(n)….why i get the output a=1,n=2 when i input 1,2 and suppose this.a=1,this.n=2?

class task1 {
public:
    int a;
    int n;
    int p, q;
    task1(int a, int n) :a(a), n(a), p{ n }, q(n){
        cout << a << " " << n << " " << p << " " << q << endl;
    }
    

};
void main() {
    task1 t1 = task1(1, 2);

}

i input 1 2 and suppose it output 1 1 2 1

but actually it output 1 2 2 2

why?

Source: Windows Questions C++

LEAVE A COMMENT