我有我的pod类型:
struct TexImageParams2D
{
/*! Width of the texture image */
GLsizei width;
/*! Height of the texture image */
GLsizei height;
/*! Pointer to image data */
const GLvoid *pixels;
/*! For efficiency we don't like to sent texture image over and over again.
* \param[in] rhs The new texture params which will be compared with this one
*/
bool operator !=( const TexImageParams2D& rhs )
{
return !(width == rhs.width && height == rhs.height && pixels == rhs.pixels);
}
/*! We check is this struct is instantiated with proper values by checking the data pointer */
bool isActive()
{
return pixels;
}
/*! When this class is reseted we use this method to reset vales */
void clear()
{
width = 0;
height = 0;
pixels = nullptr;
}
};
这适用于gcc 4.8
RendererStateTextureUnits::TexImageParams2D temp = RendererStateTextureUnits::TexImageParams2D{ width, height, pixels};
但亲爱的vs 2010编译器唠叨如下:
error C2275: 'Graphics::RendererStateTextureUnits::TexImageParams2D' : illegal use of this type as an expression
error C2143: syntax error : missing ';' before '{'
error C2143: syntax error : missing ';' before '}'
POD初始化是不是很老的功能,甚至在C中都支持?为什么VS2010唠叨呢?如果VS2010不支持Visual Studio开始支持POD括号初始化的版本?
答案 0 :(得分:4)
使用花括号{}
的统一初始化是在C ++ 11标准中引入的,Visual Studio 2010编译器没有实现该标准。
尝试改为
RendererStateTextureUnits::TexImageParams2D temp = { width, height, pixels};