Is it assignment operator ?

Hi,

I have a doubt that, suppose if we have a class call account and objects are current and saving.

1
2
account current(125,6);
account saving=current; // Question: is it work as assignment operator mechanism? or something else? 


thanks..
Thank-You so much....!
account saving=current;


account saving = current;
account saving(current);

Above are copy constructor call.

account saving;
saving = current;

Above is assignment operator mechanism. Note the subtle statement change implies different meaning altogether. C++ is so flexible that sometimes I am "afraid" :O


sohguanh wrote:
C++ is so flexible that sometimes I am "afraid" :O

Well, Java isn't bad at this either... ;)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Int
{
    private int data;

    public Int(int n) {data=n;}

    public void set(int n) {data=n;}

    @Override
    public String toString()
        {return Integer.toString(data);}
}

public class Main
{
    public static void main(String[] args)
    {
        int a=10;
        int b=a; //deep copy

        Int A=new Int(10);
        Int B=A; //shallow copy

        b=5;
        B.set(5);

        System.out.println(a); //10
        System.out.println(A); //5
    }
}
Last edited on
C++ is so flexible that sometimes I am "afraid" :O


I think if you have the sort of mind that runs on rails then you will struggle with C++.

You need a flexible mind and be the sort of person who can quite happily
live with lots of seemingly contradictory stuff.
Last edited on
Topic archived. No new replies allowed.