关于typedef定义数组类型的问题
存在以下程序:
#include<iostream>
using namespace std;
typedef int[10] array;
void main()
{
array a={12,34,56,78,90,98,76,85,64,43};
array &b=a;
a[2]=100;
for(int i=0;i<10;i++)
cout<<b[i]<<" ";
}
我感觉typedef int[10] array;应该写成typedef int[10] array;因为a数组是10个元素的int类型数组,所以我觉得应该写成typedef int[10] array;结果编译出错,错误信息如下:
--------------------Configuration: Test - Win32 Debug--------------------
Compiling...
CopyTest.cpp
d:\Test\CopyTest.cpp(4) : warning C4091: 'typedef ' : ignored on left of 'int' when no variable is declared
d:\Test\CopyTest.cpp(4) : error C2143: syntax error : missing ';' before '['
d:\Test\CopyTest.cpp(4) : error C2143: syntax error : missing ';' before '['
d:\Test\CopyTest.cpp(7) : error C2065: 'array' : undeclared identifier
d:\Test\CopyTest.cpp(7) : error C2146: syntax error : missing ';' before identifier 'a'
d:\Test\CopyTest.cpp(7) : error C2065: 'a' : undeclared identifier
d:\Test\CopyTest.cpp(7) : error C2059: syntax error : '{'
d:\Test\CopyTest.cpp(7) : error C2143: syntax error : missing ';' before '{'
d:\Test\CopyTest.cpp(7) : error C2143: syntax error : missing ';' before '}'
d:\Test\CopyTest.cpp(8) : error C2065: 'b' : undeclared identifier
d:\Test\CopyTest.cpp(8) : error C2106: '=' : left operand must be l-value
d:\Test\CopyTest.cpp(9) : error C2109: subscript requires array or pointer type
d:\Test\CopyTest.cpp(9) : error C2106: '=' : left operand must be l-value
d:\Test\CopyTest.cpp(11) : error C2109: subscript requires array or pointer type
Error executing cl.exe.
Test.exe - 13 error(s), 1 warning(s)
我的理解哪里出了问题?为什么typedef int[10] array;反而是对的?谢谢。