// I have to write it like this to compile
int w = Width + CMyClass.Width;
int h = Height + CMyClass.Height;
return new CMyClass(w,h);
}

this is not an answer but another question:
aren't Width and Height private? you should not be able
to access them at all.
what happens if they are not private (or protected)?

opAdd is a member function of CMyClass. Thus it has access to all private
members of
CMyClass.
Maybe you are confusing Class and Object. "private" blocks on a per class/type
level and not
on the object level.
Thomas

// I have to write it like this to compile
int w = Width + CMyClass.Width;
int h = Height + CMyClass.Height;
return new CMyClass(w,h);
}

this is not an answer but another question:
aren't Width and Height private? you should not be able
to access them at all.
what happens if they are not private (or protected)?

opAdd is a member function of CMyClass. Thus it has access to all private
members of
CMyClass.
Maybe you are confusing Class and Object. "private" blocks on a per class/type
level and not
on the object level.
Thomas

The problem I have is with c.Width: in java it's not visible.
As I said before, I don't care how it works on C++.
(I did confuse the code I cut of with the one I left in...)
I don't confuse Class and Object. ;)
D confuses class and object! :(
I use to like C++ but that was over 10 years (10? anyway, a long time) ago.
Ant

// I have to write it like this to compile
int w = Width + CMyClass.Width;
int h = Height + CMyClass.Height;
return new CMyClass(w,h);
}

this is not an answer but another question:
aren't Width and Height private? you should not be able
to access them at all.
what happens if they are not private (or protected)?

opAdd is a member function of CMyClass. Thus it has access to all private
members of
CMyClass.
Maybe you are confusing Class and Object. "private" blocks on a per class/type
level and not
on the object level.
Thomas

The problem I have is with c.Width: in java it's not visible.
As I said before, I don't care how it works on C++.
(I did confuse the code I cut of with the one I left in...)
I don't confuse Class and Object. ;)
D confuses class and object! :(
I use to like C++ but that was over 10 years (10? anyway, a long time) ago.
Ant

Maybe I can give some enlightenment here. In Java, each protection
attribute is on object level. That is, an instantiated object of type X
may not access a protected member of another object of the same type (X).
In D, protection attributes are per module basis. This means that any
object, method and template can access any protected attribute at any
level within the same module.
For example, in D the following would work:
module x;
class X {
private int i;
static void usesX() {
X x;
int j = x.i;
}
}
in Java, the same code would (correctly) fail, since usesX is static and
may not access the private attribute i.
N.B. Protection levels are needed to keep other modules out. This also
means that classes are automatically friends of themselves.
Regards,
Sjoerd

Maybe I can give some enlightenment here. In Java, each protection
attribute is on object level. That is, an instantiated object of type X
may not access a protected member of another object of the same type (X).
In D, protection attributes are per module basis. This means that any
object, method and template can access any protected attribute at any
level within the same module.
For example, in D the following would work:
module x;
class X {
private int i;
static void usesX() {
X x;
int j = x.i;
}
}
in Java, the same code would (correctly) fail, since usesX is static and
may not access the private attribute i.

code: (Java)
# class X {
# private int i;
#
# static void usesX() {
# X x = new X();
# int j = x.i;
# }
#
# public static void main(String args[]){
# usesX();
# }
#}
does compile and behaves like a D class.
The access rights are the same for D and Java. The only difference is, that all
classes in a
D module(one source file) have the same access rights as if they where inner
classes in an
Java class named like the D module.
Thomas

// if I write it like this, the compiler cashes and give the following
error
// error : class constructor call must be in a constructor.
// code : return this ( Width + c.Width, Height + c.Height);

did the compiler really "crash"? or did it just stop compiling because of
the error? When I try it I get the error and the compiler stops without
crashing. This is what I would expect. The error message explains what is
wrong with the code.

// and if I write it like this , it gives the following error
// error : this.Width + CMyClass.Width is not an lvalue
// code :return new CMyClass ( Width + c.Width, Height + c.Height);

This code works for me. Are you sure you didn't declare the constructor
arguments as inout or pointers or something?

// I have to write it like this to compile
int w = Width + CMyClass.Width;
int h = Height + CMyClass.Height;
return new CMyClass(w,h);
}
Is this wright or what?! and Why it gives these errors?

ok, now I have D here.
1 - return this() is not valid you use "new" to create a new instance
2 - the second version compiles on linux dmd 0.105 and gives the
expected you expected. I expected that c.Width and c.Height would
not be visible. If I remember correctly every anything on the same
scope is accessible indepentently of the access modifier
(I don't like that)
3 - the final version adds to itself, ignoring the object c.
Prefixing with the class name gives the current object (I think)
(I don't like that)
4 - variables should start with a lower case char.
Ant

error
// error : class constructor call must be in a constructor.
// code : return this ( Width + c.Width, Height + c.Height);
// and if I write it like this , it gives the following error
// error : this.Width + CMyClass.Width is not an lvalue
// code :return new CMyClass ( Width + c.Width, Height + c.Height);
// I have to write it like this to compile
int w = Width + CMyClass.Width;
int h = Height + CMyClass.Height;
return new CMyClass(w,h);
}
Is this wright or what?! and Why it gives these errors?

ok, now I have D here.
1 - return this() is not valid you use "new" to create a new instance
2 - the second version compiles on linux dmd 0.105 and gives the
expected you expected. I expected that c.Width and c.Height would
not be visible. If I remember correctly every anything on the same
scope is accessible indepentently of the access modifier
(I don't like that)
3 - the final version adds to itself, ignoring the object c.
Prefixing with the class name gives the current object (I think)
(I don't like that)
4 - variables should start with a lower case char.
Ant