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
Order of member initialization [message #58863] Tue, 20 September 2022 11:19 Go to previous message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi,

After quite some decades I feel like a newbie again. When I run:

#include <Core/Core.h>

using namespace Upp;

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

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

CONSOLE_APP_MAIN{
	B b;
}


I would expect to see item count zero in both constructors. However, in Windows on CLANGx64 it is 1 in A and 0 in B. This is true in both release and debug modes.

In MSBT22x64 it is correctly zero in release mode, but it can be any number in debug mode causing severe trouble.

Is there a way to re-order the initialization of class B so that the array gets initialized before class A?

Best regards,

Tom
 
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: Sat Apr 27 08:59:53 CEST 2024

Total time taken to generate the page: 0.04259 seconds