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