给定环境的体素化和具有顶点A,B和C的三角形,确定三角形"占据"或居住的哪些体素的最佳方法是什么?换句话说,我怎样才能枚举三角形的任何部分所在的所有体素?
我正在关注Stephan T. Lavavej的视频讲座,即关于移动语义的视频讲座:http://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-/ C9-讲座-斯蒂芬-T-Lavavej -标准-模板库- STL-9的-N
在讲座中,Stephan给出了一个名为remote_integer的示例类,并定义了一个全局函数,如下所示:
remote_integer square(const remote_integer &r) {
const int i = r.get();
return remote_integer(i*i);
}
Run Code Online (Sandbox Code Playgroud)
类remote_integer包含一个移动构造函数,但是,我注意到在尝试初始化一个新对象时调用函数square时,移动构造函数不能按预期工作.
这是代码:
remote_integer a(8);
// Expect move constructor to be called
remote_integer b = square(a);
Run Code Online (Sandbox Code Playgroud)
当我按如下方式更改square的函数定义时,move构造函数按预期工作.
remote_integer square(const remote_integer &r) {
const int i = r.get();
remote_integer local(i*i);
return local;
}
Run Code Online (Sandbox Code Playgroud)
为什么在第二种情况下调用移动构造函数,而不是在第一种情况下调用?显然在修改后的square函数中,remote_integer本地是函数的作用域,因此很明显在返回变量local时调用move构造函数.但是,当我返回第一个函数定义中的匿名对象时,为什么不会出现这种情况?