【发布时间】:2016-07-10 16:37:06
【问题描述】:
您好,我是 C++ 新手,我在根据构造函数参数初始化数组时遇到问题。
我想用 C# 做什么:
class Surface
{
public int[] pixels;
public Surface(int w, int h)
{
pixels = new int[w * h];
}
}
我现在在 C++ 中拥有的东西:
class Surface
{
private:
GLuint pixels[];
public:
Surface(int w, int h) {pixels(w * h) } //Initialize pixels based on width and height
~Surface();
};
谢谢
【问题讨论】:
-
你不是很清楚到底是什么问题。您是在询问编译错误吗?另外,我在这两个版本中看到的一个大问题是您没有保存宽度和高度,只保存了总表面积。
-
pixels = new int[w*h]这将在堆上初始化数组。 -
@JanVanBergen 编辑您的问题以更清楚地了解您的具体要求是个好主意。
标签: c++ arrays constructor