可视C++ - 无法获取列表框项的文本值,错误 C2872:'Text':不明确的符号


myWarcraftRace->removeSkill( sysStringToCharArray( listBox_mySkills->SelectedItem->Text ) );

syStringToCharArray()确实工作,也removeSkill()确实工作,问题是我无法获得listBox_mySkills->SelectedItem的文本值

如果我像上面那样做,它会给我错误:

1>d:programmingvc++ projectswcrace makerMainForm.h(194): error C2872: 'Text' : ambiguous symbol
1>          could be 'System::Drawing::Text'
1>          or       'System::Text'
1>d:programmingvc++ projectswcrace makerMainForm.h(194): error C2882: 'Text' : illegal use of namespace identifier in expression

如果我试着在没有文本的情况下使用它,它会给我错误:

1>d:programmingvc++ projectswcrace makerMainForm.h(194): error C2664: 'sysStringToCharArray' : cannot convert parameter 1 from 'System::Object ^' to 'System::String ^'

它显然应该这样做,因为sysStringToCharArray()接受System::String^参数。问题是我无法使用列表框项的Text属性,有人知道为什么吗?

您在这里没有得到一个很大的错误消息。真正的问题是ListBox::SelectedItem属性的类型。它是对象,列表框可以存储任何类型的值或对象。Object没有Text属性。现在,编译器在搜索"Text"标识符并在多个名称空间名称中找到匹配项时,会自动停止工作。解决办法:

listBox_mySkills->SelectedItem->ToString()

最新更新