编程论坛's Archiver

dafengxu 发表于 2007-7-24 01:53

[求助]:如何用枚举形做数组下标

大家好,请问在VC2005下如何用枚举类型作数组下标啊?<BR><BR>部分原代码:<BR>..............<BR>public:<BR>        enum class TextBoxIndices<BR>        {<BR>            ACCOUNT,<BR>            FIRST,<BR>            LAST,<BR>            BALANCE<BR>        };<BR><BR>................<BR>public: void SetTextBoxValues(array&lt;String ^&gt; ^values)<BR>            {<BR>                if (values-&gt;Length != TextBoxCount)<BR>                {<BR>                    throw (gcnew ArgumentException(String::Concat(<BR>                        L"There must be ", (TextBoxCount + 1).ToString(), L" strings in array")));<BR>                }<BR>                else<BR>                {<BR>                    this-&gt;txb_Account-&gt;Text = values[TextBoxIndices::ACCOUNT];<BR>                    this-&gt;txb_LastName-&gt;Text = values[TextBoxIndices::LAST];<BR>                    this-&gt;txb_FirstName-&gt;Text = values[TextBoxIndices::FIRST];<BR>                    this-&gt;txb_Balance-&gt;Text = values[TextBoxIndices::BALANCE];<BR>                }<BR>            }<BR>编译出错,显示下标类型没有转换。<BR>错误    1    error C2440: 'initializing' : cannot convert from 'BankLibrary::BankUIForm::TextBoxIndices' to 'int'    i:\visual studio 2005\projects\banklibrary\banklibrary\BankUIForm.h    204   <BR>错误    2    error C3262: invalid array indexing: 0 dimension(s) specified for 1-dimensional 'cli::array&lt;Type,dimension&gt; ^'    i:\visual studio 2005\projects\banklibrary\banklibrary\BankUIForm.h    204    <BR> <BR><BR>

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.