无法在 VS 2010 中使用括号初始化 POD 类型?
Initializing POD types with parenthesis in VS 2010 not possible?
我有我的广告连播类型:
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括号初始化?
C++11 标准中引入了使用大括号 {}
的统一初始化,Visual Studio 2010 编译器未实现。
试试看
RendererStateTextureUnits::TexImageParams2D temp = { width, height, pixels};
我有我的广告连播类型:
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括号初始化?
C++11 标准中引入了使用大括号 {}
的统一初始化,Visual Studio 2010 编译器未实现。
试试看
RendererStateTextureUnits::TexImageParams2D temp = { width, height, pixels};