Sunday 15 September 2013

java - Polymorphism and Inheritance in C++ -



java - Polymorphism and Inheritance in C++ -

so in java had next implementation:

public abstract class pfigure implements comparable

and java implementation inheritance , polymorphism:

public class pfigurelist { private final int max_vehicles = 9; private pfigure list[] = new pfigure[max_vehicles]; private int count = 0; /** adds pfigure list if list not total , increments count. @param myfig "vehicle" pfigure going added list */ public void add(pfigure myfig) { if(count <= 9) list[count++] = myfig; } /** every figure in list, calls hide() function, polymorphic move() function, , draw() function show now. */ public void move() { for(int = 1; < count; i++) { list[i].hide(); list[i].move(); list[i].draw(); } }

now want accomplish except similar in c++. here code:

void vbotlist::add(vbot * add) { vbot[count++] = add; } void vbotlist::move() { /*for(int = 0; < list.getcount(); i++) list.getvalue(i)->move();*/ for(int = 0; < count; i++) vbot[i]->move(); } class vbotlist { private: int count; vbot * vbot[50]; public: vbotlist() : count(0){ } void add(vbot * vbot); void move(); void show(); }; public ref class myform : public system::windows::forms::form { public: myform(void) { initializecomponent(); // //todo: add together constructor code here // } static vbotlist * list = new vbotlist();

and effort implement it:

private: system::void speedtimer_tick(system::object^ sender, system::eventargs^ e) { list->move(); invalidate(); speedtimer->interval = speedtrackbar->value; } private: system::void vbotaddbutton_click(system::object^ sender, system::eventargs^ e) { if(combobox1->selectedindex == 1) { vbot * x = new billybot(system::convert::toint32(textbox1->text), system::convert::toint32(textbox2->text), panel1); list->add(x); } } private: system::void panel1_paint(system::object^ sender, system::windows::forms::painteventargs^ e) { list->show(); }

my goal here take vbot object stored in vbotlist, pfigurelist of pfigure objects in java. have no clue why, cannot display object on panel. had create initialization of vbotlist static in order not give me error messages. missing obvious or doing wrong displaying object? hints, advice, or slap on hand code great.

show() displays image. i'll post code if needed.

you work in c++/cli, you're class must managed too, illustration :

ref class bot { public: bot() { } }; ref class vbotlist { private: int m_count; array<bot ^> ^vbot; public: vbotlist() : m_count(0), vbot(gcnew array<bot ^>(50)) { } void add(bot ^newbot) { vbot[m_count++] = newbot; } int getcount() { homecoming m_count; } };

and next :

private: vbotlist ^list; public: form1(void) { initializecomponent(); list = gcnew vbotlist(); label1->text = system::convert::tostring(list->getcount()); } // ... private: system::void button1_click(system::object^ sender, system::eventargs^ e) { bot ^bot = gcnew bot(); list->add(bot); label1->text = system::convert::tostring(list->getcount()); }

^ declare handle managed pointer.

java object c++-cli

No comments:

Post a Comment