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 » Order of member initialization
Re: Order of member initialization [message #58869 is a reply to message #58863] Tue, 20 September 2022 17:06 Go to previous messageGo to previous message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 220
Registered: June 2011
Experienced Member
I found out the same thing a while ago and then it made sense to me. The base class is initialized first, then the initializers. I think what I ended up doing to get around that, and I still don't know if it's correct, is that I would so something like create a context, a struct holding the Array as well as a function that would return *this, I'd inherit from it instead and then then I'd pass the ref function to the constructor of the second base class which would then reference it.

Looked something like this:

struct BaseA {
   Array<int> a;
   auto& BaseARef() { return *this; }
};

struct BaseB {
   BaseA& baseA;

   BaseB(BaseA& baseA) : baseA(baseA) {
      // do something with baseA.a;
   }
};

struct Whatever : BaseA, BaseB {
    Whatever() : BaseA(), BaseB(BaseARef()) {} 
};


It was weird and I'm not sure if it's sound - but it did work, and if anyone knows the compiler better, feel free to let me know.

[Updated on: Tue, 20 September 2022 17:08]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Can TheIDE be used in two instances?
Next Topic: Some Questions
Goto Forum:
  


Current Time: Wed May 08 07:37:21 CEST 2024

Total time taken to generate the page: 0.02784 seconds