C2070 - 非法sizeof操作数 [英] C2070 - illegal sizeof operand
本文介绍了C2070 - 非法sizeof操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码对我看起来很好:
The following code looks fine to me:
#include <stdio.h>
template <typename T>
struct A
{
static float m_kA[];
};
template <typename T>
float A<T>::m_kA[] = {1.0f, 2.0f, 3.0f};
int main()
{
printf("%d\n",
sizeof(A<unsigned int>::m_kA) /
sizeof(A<unsigned int>::m_kA[0]));
return 0;
}
但是当我用VC9编译时,得到以下错误
But when i compile with VC9 i get the following error
error C2070: 'float []': illegal sizeof operand
我希望这段代码可以编译。我错过了什么?有没有人知道一种方法来解决这个奇怪的行为(注意完全相同的事情没有模板编译精致和输出3)。
I would expect this code to compile. Am i missing something? Does anyone know a way to fix this strange behavior (note that the exact same thing without the template compiles fine and outputs 3).
请注意,删除模板不是选项,我让这个例子重现一个问题,我在一个代码中,我需要包含数组作为一个模板的类型。
Note that removing the template is not an option, i made this example to reproduce a problem that i'm having in a code where i need the type containing the array to be a template.
感谢
推荐答案
它用G ++编译得很好。
it compiles fine with G++.
与此错误相关:
这篇关于C2070 - 非法sizeof操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文