Thread overview
Properties using
Mar 31, 2008
Uwar
Mar 31, 2008
Simen Kjaeraas
Apr 01, 2008
Uwar
Apr 01, 2008
Craig Black
March 31, 2008
Error: Access Violation
When I tring run program below. What is wrong?

//  class CPart
//______________________________________________________
class CPart{

	//	utilities
	//__________________________________________________
    class CRing{
		//	data memebers
		//______________________________________________
		private{
			float m_sDia;
			float m_bDia;
		}

		//  properties
		//______________________________________________
        public{
            //	property SmallerDiameter
            //__________________________________________
            float SmallerDiameter(float o_sDia){ return m_sDia = o_sDia; }
            float SmallerDiameter(			  ){ return m_sDia		   ; }

            //	property BiggerDiameter
            //__________________________________________
            float BiggerDiameter(float o_bDia){ return m_bDia = o_bDia; }
            float BiggerDiameter(			 ){ return m_bDia		  ; }
        }
	}

	//	data members
	//__________________________________________________
	private{
		float m_length;
		CRing m_ringFirst;
		CRing m_ringSecond;
	}

    //  properties
    //__________________________________________________
    public{
        //  property Length
        //______________________________________________
        float Length(float o_length){ return m_length = o_length; }
        float Length(              ){ return m_length           ; }

        //  property RingFirst
        //______________________________________________
        CRing RingFirst(){ return m_ringFirst; }

        //  property RingSecond
        //______________________________________________
        CRing RingSecond(){ return m_ringSecond; }
    }
}

void
main(char[][] args){
    CPart part_1;
    with (part_1 = new CPart){
        auto A = RingFirst.SmallerDiameter;
    }
}
March 31, 2008
On Mon, 31 Mar 2008 22:51:53 +0200, Uwar <uwar@o2.pl> wrote:

> Error: Access Violation
> When I tring run program below. What is wrong?
>
> [Snip]

m_ringFirst is never initialized. Create a constructor and add m_ringFirst = new CRing();. Should fix it.

-- Simen
April 01, 2008
Looks like you are coming from C++ and expect classes to serve as value types.  This is not true in D.  Like C#, classes are reference types and structs are value types.  You may want to use structs instead of classes.

-Craig

April 01, 2008
Great! It is working. Thanks a lot.