我使用了示例 here将我的镶嵌回调移动到不同的类。
代码编译,但回调代码永远不会执行。
回调类:
template <class Class, typename ReturnType, typename Parameter>
class SingularCallBack
{
public:
typedef ReturnType (Class::*Method)(Parameter);
SingularCallBack(Class* class_instance, Method method)
: class_instance_(class_instance),
method_(method)
{}
ReturnType operator()(Parameter parameter)
{
return (class_instance_->*method_)(parameter);
}
ReturnType execute(Parameter parameter)
{
return operator()(parameter);
}
private:
Class* class_instance_;
Method method_;
};
回调:
void MyClass::tessBegin(GLenum which)
{
glBegin(which);
cout << "BEGIN CALLBACK IS WORKING";
}
void MyClass::tessVertex(const GLvoid *data)
{
// cast back to double type
const GLdouble *ptr = (const GLdouble*)data;
glVertex3dv(ptr);
cout << "VERTEX CALLBACK IS WORKING";
}
我在其中注册它们的镶嵌函数:
int MyClass::TessellatePolys()
{
GLUtesselator *tess = gluNewTess(); // create a tessellator
if(!tess) return 0; // failed to create tessellation object, return 0
// register callback functions
SingularCallBack<GLOrtho, void, GLenum>*BeginCallback;
BeginCallback = new SingularCallBack<GLOrtho, void, GLenum>(this,&GLOrtho::tessBegin);
gluTessCallback(tess, GLU_TESS_BEGIN, (void (CALLBACK *)())BeginCallback);
SingularCallBack<GLOrtho, void, const GLvoid*>*VertexCallback;
VertexCallback = new SingularCallBack<GLOrtho, void, const GLvoid*>(this,&GLOrtho::tessVertex);
gluTessCallback(tess, GLU_TESS_VERTEX, (void (CALLBACK *)())VertexCallback);
... (do tessellation) ...
return id;
}
回调的注册方式有什么问题?
最佳答案
您正在将指向对象类型的指针转换为指向函数类型的指针(例如,“BeginCallback”转换为“void (CALLBACK *)()”)。这些类型不兼容且不相关。代码编译为 c 风格转换,没有任何类型检查。更重要的是,从 C++ 编译器的角度来看,BeginCallback 和 VertexCallback 是不同且不兼容的类型,函数 gluTessCallback 无法调用它们的重载 operator() - 这些是不同的成员函数。
关于c++ - OpenGL 曲面 segmentation 回调未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14244406/
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
我遵循了教程http://gettingstartedwithchef.com/,第1章。我的运行list是"run_list":["recipe[apt]","recipe[phpap]"]我的phpapRecipe默认Recipeinclude_recipe"apache2"include_recipe"build-essential"include_recipe"openssl"include_recipe"mysql::client"include_recipe"mysql::server"include_recipe"php"include_recipe"php::modul
我有一个服务模型/表及其注册表。在表单中,我几乎拥有服务的所有字段,但我想在验证服务对象之前自动设置其中一些值。示例:--服务Controller#创建Action:defcreate@service=Service.new@service_form=ServiceFormObject.new(@service)@service_form.validate(params[:service_form_object])and@service_form.saverespond_with(@service_form,location:admin_services_path)end在验证@ser
我正在阅读SandiMetz的POODR,并且遇到了一个我不太了解的编码原则。这是代码:classBicycleattr_reader:size,:chain,:tire_sizedefinitialize(args={})@size=args[:size]||1@chain=args[:chain]||2@tire_size=args[:tire_size]||3post_initialize(args)endendclassMountainBike此代码将为其各自的属性输出1,2,3,4,5。我不明白的是查找方法。当一辆山地自行车被实例化时,因为它没有自己的initialize方法
我在用Ruby执行简单任务时遇到了一件奇怪的事情。我只想用每个方法迭代字母表,但迭代在执行中先进行:alfawit=("a".."z")puts"That'sanalphabet:\n\n#{alfawit.each{|litera|putslitera}}"这段代码的结果是:(缩写)abc⋮xyzThat'sanalphabet:a..z知道为什么它会这样工作或者我做错了什么吗?提前致谢。 最佳答案 因为您的each调用被插入到在固定字符串之前执行的字符串文字中。此外,each返回一个Enumerable,实际上您甚至打印它。试试
如何检查Ruby文件是否是通过“require”或“load”导入的,而不是简单地从命令行执行的?例如:foo.rb的内容:puts"Hello"bar.rb的内容require'foo'输出:$./foo.rbHello$./bar.rbHello基本上,我想调用bar.rb以不执行puts调用。 最佳答案 将foo.rb改为:if__FILE__==$0puts"Hello"end检查__FILE__-当前ruby文件的名称-与$0-正在运行的脚本的名称。 关于ruby-检查是否
如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:
//1.验证返回状态码是否是200pm.test("Statuscodeis200",function(){pm.response.to.have.status(200);});//2.验证返回body内是否含有某个值pm.test("Bodymatchesstring",function(){pm.expect(pm.response.text()).to.include("string_you_want_to_search");});//3.验证某个返回值是否是100pm.test("Yourtestname",function(){varjsonData=pm.response.json
我从Ubuntu服务器上的RVM转移到rbenv。当我使用RVM时,使用bundle没有问题。转移到rbenv后,我在Jenkins的执行shell中收到“找不到命令”错误。我内爆并删除了RVM,并从~/.bashrc'中删除了所有与RVM相关的行。使用后我仍然收到此错误:rvmimploderm~/.rvm-rfrm~/.rvmrcgeminstallbundlerecho'exportPATH="$HOME/.rbenv/bin:$PATH"'>>~/.bashrcecho'eval"$(rbenvinit-)"'>>~/.bashrc.~/.bashrcrbenvversions