调用功能并将其设置为等于结构
calling a function and setting it equal to a struct
有人可以解释第12行中的情况吗?我如何设置一个等于struct(矩阵(的函数;
mat4& getCurrentMatrix() {
if(currentMatrixMode == MGL_PROJECTION) {
return projMatrix;
}
else { //Not sure if we need to account for MGL_TEXTURE or MGL_COLOR
//yet
return modelViewMatrix;
}
}
void setCurrentMatrix(mat4 matrix) {
getCurrentMatrix() = matrix; //what is going on in here?
}
您没有设置与其他对象相等的函数,而是将函数的结果分配给另一个对象。
如果该函数返回某些对象或值(但没有引用(,则没有有用的效果(除非=
运算符被副作用覆盖以副作用!(,例如在C语言中。
但是,在C 中,您可以返回全局/高范围对象的参考
它可以做一些有用的事情,因为该函数返回某些全局/更高范围对象上的参考,因此等同于:
modelViewMatrix = matrix;
或
projMatrix = matrix;
取决于函数的参数
getCurrentMatrix
功能返回对mat4
的引用。引用的是将其设置为等于传递给函数的矩阵的mat4
。
相关文章:
- 特定于目录结构的生成文件
- c ++数据输入并读回列表中的结构结构中的数组
- 相当于 Java 中的C++结构
- 如何创建结构的结构结构,等等嵌套多个结构?
- C++中用于结构的纯数组的类似于TableView/DataFrame的通用功能
- 适用于频繁更改的大型数据集的最佳数据结构
- C++类似于 std::map 的数据结构,具有多个键级别
- 使用带有结构结构作为 C++; 元素的单向链表
- 结构化绑定:当某些内容看起来像引用并且行为类似于引用,但它不是引用时
- 类相对于数据结构的重要性
- 易失性结构 = 结构不可能,为什么?
- 返回带有动态结构数组的结构结构
- 功能指针强制沿着班级结构结构
- 遵循来自源文件的结构结构
- C++/CLI(.NET)等效于将结构写入网络的本机C++
- 当函数在fread()应用于局部结构变量后返回时发生访问冲突
- 有条件地初始化一个结构体字段——仅当它存在于该结构体中时
- 可变类/结构结构?(不是模板而不是工会?
- 标准异常层次结构结构的原因
- 并集对象的行为类似于一个结构