class and opCall
BLS
nanali at nospam-wanadoo.fr
Mon Jan 7 04:52:11 PST 2008
BLS schrieb:
> Hi,
> in another context I ask what this piece of C++ code means ...
> //C++
> CPoint = {0}
>
> bb explains that I can use :
> CPoint p = {0,0};
> Jarret adds
> .....except that if this isn't a static struct declaration, you have to
> write:
> CPoint p = CPoint(0,0)
> // Well I talked about a class instead a struct, but nevertheless
>
> Okay, let's assume that my point class has three member vars as shown in
> the example.
> How the compiler knwows, which member I mean ?
> I think I have to implement opCall explicit ...
> class CPoint
> {
>
> static CPoint opCall(int _x, int _y)
> {
> CPoint cp;
> cp.x = _x;
> cp.y = _y;
> return cp;
> }
> private:
> int x;
> int z; // extra member, just to demonstrate what I mean.
> int y;
> }
> ....
> to use CPoint as parameter
>
> void movePoint(CPoint p, bool changecolor = true)
> {
> // do something
> }
> //use it as
> movePoint(CPoint(10,2));
>
> Do I miss something here ?
>
> Next :
> C++
> class CFont
> {
> public:
> HFONT m_hFont;
> operator HFONT() {return m_hFont;}
> }
>
> Actually D doen't support this kind of operator overloading.
> Do you see a chance that opCall in conjunction with alias is a
> reasonable workaround ?
>
> given opCall :
> opCall() {return this.m_hFont;}
>
> and than something similar to :
> alias opCall() HFONT() ; // :( don't have the syntax in my mind
>
> Thanks in advance Bjoern
should be :
alias opCall HFONT;
More information about the Digitalmars-d-learn
mailing list