[C++-sig] operator problem

gaoyakun gaoyakun at sina.com
Thu Nov 14 04:00:26 CET 2002


I have exported my point3 class to python, with many overloaded operators. it works fine for me except the *= operator. it always tell me "can't multiply sequence with non int type". but if i use p1.__imul__(p2) instead of p1 *= p2, it successfully executed my code. what's wrong with me? this is some code of my point3 class
 
class point3
{
  .. ...
  point3 & operator *= (const point3 &p)
  {
    v[0] *= p.v[0]; v[1] *= p.v[1]; v[2] *= p.v[2];
    return *this; 
  }
  point3 & operator *= (float t)
  {
    v[0] *= t; v[1] *= t; v[2] *= t;
    return *this;
  }
  ....
};
 
in to_python.cpp:
 
class_<point3>("point3")
... ...
.def(self *= self)
.def(self * self)
.def(self *= other<float>())
.def(self * other<float>())
... ...
 
what's the problem?
______________________________________

===================================================================
Ãâ·ÑÊÔÓÃÐÂÀË15MÊÕ·ÑÓÊÏä ¸Ï½ôÐж¯£¡ (http://vip.sina.com/sol_mail/promotion/pro_men.html)
ÐÂÀ˶þÊÖÊг¡£ºÒ»ÔªÍ¶È룬ʮ·Ö¾ªÏ²£¬°Ù·ÖÂúÒâ (http://classad.sina.com.cn/2shou/)
ÊýÍòÕÅÊÖ»úͼƬÊýÍòÊ׶ÌÐÅÁåÉùÈÎÄãÌôÑ¡£¬Ã¿Ì춼ÓиüР(http://sms.sina.com.cn/cgi-bin/sms/smspic.cgi)




More information about the Cplusplus-sig mailing list