[C++-sig] Getting operator[]() to throw RangeError using py++

David Wolfe dwolfe at gforcetech.com
Sun Jan 6 02:23:55 CET 2008


Using py++, can anyone help me figure out how to get operator[]() to
throw a RangeError for some vector classes I'm trying to wrap?  The
default behavior is a bit undesirable:

 >>> import osg
 >>> v = osg.Vec3f(1,2,3)
 >>> v.x
1.0
 >>> v.y
2.0
 >>> v.z = -1
 >>> v[0]
1.0
 >>> v[1]
2.0
 >>> v[2]
-1.0
 >>> v[3]
1.4326351413631272e-038
 >>> v[100]
0.0
 >>> v[-10]
1.0636871398322276e+037
 >>>

How can I firewall off 'garbage' index values from operator[]()?

Any advice much appreciated... :-)

TIA,

- Dave W.





More information about the Cplusplus-sig mailing list