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 previous 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
 
Read Message
Read Message
Read Message
Previous Topic: MSSQL and codepage
Next Topic: Protect and Web
Goto Forum:
  


Current Time: Fri Apr 26 11:15:09 CEST 2024

Total time taken to generate the page: 2.13439 seconds