Sep 27, 2010 at 3:31am UTC
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 Sep 27, 2010 at 3:47am UTC
Sep 27, 2010 at 3:37am UTC
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 Sep 27, 2010 at 3:37am UTC