KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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; } But when i compile with VC9 i get the following error error C2070: 'float []': illegal sizeof operand 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. Thanks
Tags (comma-separated)
Save Edits
Cancel