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 » U++ Library support » U++ Core » Is there a way to fetch objects w/o default constructor?
Re: Is there a way to fetch objects w/o default constructor? [message #18054 is a reply to message #18052] Mon, 08 September 2008 19:23 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14265
Registered: November 2005
Ultimate Member
Mindtraveller wrote on Mon, 08 September 2008 05:25

Simplified code as a description of problem:
class Project
{
    Project(TabCtrl &tabs) {/*add new tab with Project controls*/}
};

class App
{
    void Serialize (Stream &stream) {stream % projects;} //ERROR: no default constructor available
    Array<Project> projects;
    TabCtrl        mainTabs;
};


Is there a way I can fetch my Project objects with auto-adding to the tabs?


Yes, but not really recomended Smile

The trick would be to implement your own Array serialization, using "new" variant of Add.

Something like:

if(s.IsLoading())
    projects.Clear();
int count = projects.GetCount();
s % count;
for(int i = 0; i < count; i++)
    if(s.IsStoring())
        s % projects[i];
    else
        s % projects.Add(new Project(tabs));


(I would rather find some other solution. IMO, except special cases, classes should have default constructors).

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Full Support for timezone/DST [FEATURE REQUEST]
Next Topic: CR visibile with notepad
Goto Forum:
  


Current Time: Tue Jul 08 11:16:29 CEST 2025

Total time taken to generate the page: 0.03276 seconds