digitalmars.D.learn - Properties using
- Uwar (62/62) Mar 31 2008 Error: Access Violation
- Simen Kjaeraas (5/8) Mar 31 2008 m_ringFirst is never initialized. Create a constructor and add m_ringFir...
- Uwar (1/1) Mar 31 2008 Great! It is working. Thanks a lot.
- Craig Black (4/4) Mar 31 2008 Looks like you are coming from C++ and expect classes to serve as value
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;
}
}
Mar 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_ringFir= st = =3D new CRing();. Should fix it. -- Simen
Mar 31 2008
Looks like you are coming from C++ and expect classes to serve as value structs are value types. You may want to use structs instead of classes. -Craig
Mar 31 2008









Uwar <uwar o2.pl> 