错误:'textureID'是'Texture'的私有成员
Error: 'textureID' is a private member of 'Texture'
错误的解决方案是什么,"textureID是Texture的私有成员。"Texture是一个类,textureID为无符号整数。程序运行的图像是一个24位未压缩位图(我认为)。错误出现在glBindTexture(GL_TEXTURE_2D,tex->textureID)。以下是代码的一部分。
void display() {
preProcessEvents();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
//Camera Transformations
glRotatef(Camera::rotation.x, 1, 0, 0);
glRotatef(Camera::rotation.y, 0, 1, 0);
glRotatef(Camera::rotation.z, 0, 0, 1);
glTranslatef(-Camera::position.x, -Camera::position.y, -Camera::position.z);
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(-1, 0, -3);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(0, 2, -3);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(1, 0, -3);
glEnd();
glBindTexture(GL_TEXTURE_2D, tex->textureID);
glBegin(GL_QUADS);
glColor3f(1, 1, 1);
glTexCoord2f(100, 100);
glVertex3f(100, 0, 100);
glTexCoord2f(-100, 100);
glVertex3f(-100, 0, 100);
glTexCoord2f(-100, -100);
glVertex3f(-100, 0, -100);
glTexCoord2f(100, -100);
glVertex3f(100, 0, -100);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glutSwapBuffers();
}
该类位于头文件中,代码如下。"unsigned int textureID"应该在public下吗?这可能就是错误说textureID是私有的原因吗?
#ifndef __Xcode_Glut_Tutorial__Texture__
#define __Xcode_Glut_Tutorial__Texture__
#include <iostream>
#include <OpenGL/gl.h>
using namespace std;
class Texture {
unsigned int textureID;
public:
Texture(void* data, int w, int h, int format);
static Texture* loadBMP(const char* filename);
};
#endif /* defined(__Xcode_Glut_Tutorial__Texture__) */
textureID
在Texture
类中是私有的
解决方案1:
您必须更改:
class Texture {
unsigned int textureID;
public:
Texture(void* data, int w, int h, int format);
static Texture* loadBMP(const char* filename);
};
至
class Texture {
public:
unsigned int textureID;
Texture(void* data, int w, int h, int format);
static Texture* loadBMP(const char* filename);
};
解决方案2:
使用公共getter函数:
class Texture {
unsigned int textureID;
public:
Texture(void* data, int w, int h, int format);
static Texture* loadBMP(const char* filename);
unsigned int get_textureID()
{
return textureID;
}
};
和:
glBindTexture(GL_TEXTURE_2D, tex->get_textureID());
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 对RValue对象调用的LValue ref限定成员函数
- 为什么使用 "this" 指针调用派生成员函数?
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 助记符和指向成员语法的指针
- 用于访问容器<T>数据成员的正确 API
- 内置函数可查看CPP中的成员变量
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 嵌套在类中时无法设置成员数据
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 将函数类成员映射到类本身内部
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 将Ref对象作为类成员
- 将包含C样式数组的对象初始化为成员变量(C++)
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 将公共但非静态的成员函数与ALGLIB集成
- 多成员Constexpr结构初始化
- 错误:'textureID'是'Texture'的私有成员