Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » ArrayMap / Polymorphism question (I probably do something wrong here...)
ArrayMap / Polymorphism question [message #49485] Fri, 16 February 2018 22:03 Go to next message
Kozaluss is currently offline  Kozaluss
Messages: 2
Registered: February 2018
Junior Member
Hello everyone!

I've discovered U++ yesterday and would really like to use it's potential.
But these were years since I've last used C++ - now I mainly work in Clarion - job reasons.

I am trying to write an application - it is supposed to have many different classes (machines) derived from one base class (base machine).

Then on top of that I need an array of pairs int and someclass from the set above.
I understand, that I should declare this like this:

ArrayMap<int,BaseMachine> ML;

where BaseMachine is the base class for all other machine classes.
So when I add some derived type machine, I do it this way:

ML.Add( NUID, MasterMachine() ); // NUID is generated int

Then I have a virtual method like this declared in every class:

virtual String Typ();

which now simply returns a predefined string.

And finally I have an ArrayCtrl "TabelaMaszyn" to display the contents of ML with this code:

for(int i=0;i<ML.GetCount();i++){
TabelaMaszyn->Add( ML.GetKey(i), ML[i].Typ(), ML[i].Nazwa );
}

And the problem is, that ML[i].Typ() always returns the value generated by function of the base class, instead of being polymorphic, returning the value generated in derived class, which was passed during creation of ML[i] element.

So... what am I doing wrong here?
Please be polite Smile
Thanks in advance.


Kozaluss
Re: ArrayMap / Polymorphism question [message #49486 is a reply to message #49485] Sat, 17 February 2018 08:43 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11701
Registered: November 2005
Ultimate Member
Kozaluss wrote on Fri, 16 February 2018 22:03
Hello everyone!

I've discovered U++ yesterday and would really like to use it's potential.
But these were years since I've last used C++ - now I mainly work in Clarion - job reasons.

I am trying to write an application - it is supposed to have many different classes (machines) derived from one base class (base machine).

Then on top of that I need an array of pairs int and someclass from the set above.
I understand, that I should declare this like this:

ArrayMap<int,BaseMachine> ML;

where BaseMachine is the base class for all other machine classes.
So when I add some derived type machine, I do it this way:

ML.Add( NUID, MasterMachine() ); // NUID is generated int


ML.Create<MasterMachine>(NUID);
Re: ArrayMap / Polymorphism question [message #49490 is a reply to message #49486] Sat, 17 February 2018 17:54 Go to previous message
Kozaluss is currently offline  Kozaluss
Messages: 2
Registered: February 2018
Junior Member
Wow! It is working. Many thanks Very Happy.

Kozaluss
Previous Topic: MSSQL and codepage
Next Topic: Protect and Web
Goto Forum:
  


Current Time: Tue Feb 19 10:26:50 CET 2019

Total time taken to generate the page: 0.00558 seconds