c++ - 尝试将 **varname 分配给 *varname[] 时出现问题。 C++

标签 c++

在我的 .h 中,我有一个变量,Texture ** skyboxTextures。我在一种方法中分配了一些纹理指针,并立即使用它们:

Texture *skt[] = { 
    tleft,
    tright,
    tfront,
    tback,
    tup,
    tdown
};
skyboxTextures = skt;

for(int i = 0; i < 6; i++)
{
    skyboxTextures[i]->load();
}

然后我稍后在另一种方法中尝试再次使用纹理。

Texture *skt[] = skyboxTextures;

// Render the front quad
skyboxTextures[0]->activate();

这是我的问题,我无法再访问我的对象。由于此错误,这将无法编译:

error C2440: 'initializing' : cannot convert from 'Texture **' to 'Texture *[]'

如果我注释掉行 Texture *skt[] = skyboxTextures;,我得到的只是无效的纹理指针。

最佳答案

您不能分配数组。不幸的是,很难确切知道建议的内容,因为您只提供了一小段代码。但是,我建议阅读此书:http://c-faq.com/aryptr/index.html .

关于c++ - 尝试将 **varname 分配给 *varname[] 时出现问题。 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4950411/

相关文章:

c++ - Qt如何删除QObjects?

c++ - boost 日期时间 : time_duration from seconds to multiple days

c++ - prim_minimum_spanning_tree() boost 函数

c++ - 替换以空格分隔的字符串 C++ 中的字段

c++ - 拆分参数包

C++ ~ 在客户端调用函数给出错误 : "identifier ____ is undefined"

c++ - 标量和强制调用站点的可读性?

c++ - 在 C++ 中查看析构函数

c++ - Openmp线程休眠

c++ - 算法在计算时很快 - 将计算数据写入输出缓冲区时速度很慢