#include#include int main() { BList list; list.AddItem(new BString("apple")); list.AddItem(new BString("banana")); list.AddItem(new BString("cherry")); BString* item = static_cast (list.ItemAt(1)); std::cout << "Second item: " << *item << std::endl; return 0; }
#includeThis example creates a BMenu and adds three BMenuItem objects to it. It then retrieves the second item in the menu using the ItemAt function and casts it to a BMenuItem pointer using the dynamic_cast<> operator. Finally, it prints the label of the second item to the console. In both examples, the BList/ItemAt function and BMenu/ItemAt function are part of the BeOS API library.#include int main() { BMenu* menu = new BMenu("File"); menu->AddItem(new BMenuItem("New")); menu->AddItem(new BMenuItem("Open")); menu->AddItem(new BMenuItem("Save")); BMenuItem* item = dynamic_cast (menu->ItemAt(1)); std::cout << "Second item: " << item->Label() << std::endl; return 0; }