<div><br><div id="mb_0"><div><div>Hi, sorry for another problem... i have a simple question to ask... <br><br><br>lets say say i have base class<br><br><br>struct GeomObject<br>{</div> <div> // draws an wire shape</div> <div> virtual void drawAbstract(const GLfloat& x, const GLfloat& y, const GLfloat& z) = 0; </div> <div> // draws a solid shape.</div> <div> virtual void drawSolid(const GLfloat& x, const GLfloat& y, const GLfloat& z) = 0;</div> <div>}<br><br><br>Now i have bunch of stuff that inherits it..<br><br>Like class Circle, class Sphere, class Cylinder, class Cone and all of them implement drawSolid and drawAbstract (radius base assumed). <br><br>I have a function call drawCircle(const std::string& r, (someBoostFunctionParam)) </div> <div>{</div> <div> Circle cir(4.0, r); // construct a circle with radius 4.0 and name r</div> <div> cir.someBoostFunctionParam(x, y, z);</div> <div>}<br><br>thus if i say drawCircle("solid", &Circle::drawSolid);<br>drawCircle("abstract", &Circle::drawAbstract);<br></div> <div> </div> <div> </div> <div>How do you do that? Or whats the best way to do it. </div> </div></div><br> </div> <div><span class="gmail_quote">On 8/22/06, <b class="gmail_sendername">Fran�ois Duranleau</b> <<a href="mailto:duranlef@iro.umontreal.ca" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">duranlef@iro.umontreal.ca </a>> wrote:</span> <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">On Mon, 21 Aug 2006, chun ping wang wrote:<br><br>[...]<br>> template <class T><br> > boost::function<void*(const T&, const T&, const T&)> getVerxFunc3() <br>> {<br>> BOOST_STATIC_ASSERT(boost::is_integral<T>::value ||<br>> boost::is_floating_point<T>::value);<br>> return (boost::is_integral<T>::value) ? &glVertex3i : &glVertex3d;<br> > }<br>><br>[...]<br>><br>> template <class T><br>> void drawDot(const T& x, const T& y, const T& z) {<br>> boost::function<void(const T&, const T&, const T&)><br> > myFunc(getVerxFunc3<T>()); <br>> glBegin(GL_POINTS);<br>> myFunc(x, y, z);<br>> glEnd();<br>> glFlush();<br>> }<br>><br>[just kept one example from the above]<br><br>Isn't using boost::function overkill here? I would rather do this: <br><br>template < typename T ><br>void gl_vertex( const T& x , const T& y , const T& z )<br>{<br> // you can use the BOOST_STATIC_ASSERT as above here, or use<br> // boost::enable_if with the same condition around the void return <br><br> if ( boost::is_floating_point< T >::value )<br> {<br> glVertex3d( x , y , z ) ;<br> }<br> else<br> {<br> glVertex3i( x , y , z ) ;<br> }<br>}<br><br>or even simply this:<br> <br> void gl_vertex( GLdouble x , GLdouble y , GLdouble z )<br>{<br> glVertex3d( x , y , z ) ;<br>}<br><br>void gl_vertex( GLint x , GLint y , GLint z )<br>{<br> glVertex3i( x , y , z ) ;<br>}<br><br>and then:<br><br>template < typename T > <br>void drawDot( const T& x , const T& y , const T& z )<br>{<br> glBegin( GL_POINTS ) ;<br> gl_vertex( x , y , z ) ;<br> glEnd() ;<br>}<br><br>That should be more efficient and, especially for the second case, is a <br>simpler to read overall.<br><br>Anyway, just my two cents.<br><br>--<br>Fran�ois Duranleau<br>LIGUM, Universit� de Montr�al<br><br>"Sacrifices are a necessary factor in creating a new destiny. A small<br>misfortune becomes the cornerstone of a greater happiness." <br> - Emperor Dornkirk, in _The Vision of Escaflowne_<br><br>_______________________________________________<br>Boost-users mailing list<br><a href="mailto:Boost-users@lists.boost.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> Boost-users@lists.boost.org </a><br><a href="http://lists.boost.org/mailman/listinfo.cgi/boost-users" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://lists.boost.org/mailman/listinfo.cgi/boost-users</a><br><br>_______________________________________________ <br>Boost-users mailing list<br><a href="mailto:Boost-users@lists.boost.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> Boost-users@lists.boost.org</a><br><a href="http://lists.boost.org/mailman/listinfo.cgi/boost-users" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://lists.boost.org/mailman/listinfo.cgi/boost-users </a><br><br></blockquote></div><br>