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 #58871 is a reply to message #58869] Tue, 20 September 2022 17:48 Go to previous messageGo to previous message
peterh is currently offline  peterh
Messages: 108
Registered: November 2018
Location: Germany
Experienced Member
I cannot discuss this, multiple inheritance is too advanced for me.

This however seems to work.
The array is allocated by new and so it is constructed before all classes are constructed and instantiated.

#include <Core/Core.h>

using namespace Upp;

class A{
public:
	Array<int> &array;
	A(Array<int> &array_) : array(array_){
		Cout() <<"construct A\n";
		array.SetCount(0);
		Cout() << "Array Initial item count in A = " << array.GetCount() << "\n";
	}
};

class B : public A{
public:
	Array<int> &b_array;
	B() : A(*(new Array<int>)),b_array(A::array){
		Cout() <<"construct B\n";
		Cout() << "Array Initial item count in B = " << b_array.GetCount() << "\n";
	}
};

CONSOLE_APP_MAIN{
	B b;
	Cout() <<"Fertig\n";
	Sleep(1000000);
}
 
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 11:43:38 CEST 2024

Total time taken to generate the page: 0.02613 seconds