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 #58866 is a reply to message #58865] Tue, 20 September 2022 15:19 Go to previous messageGo to previous message
peterh is currently offline  peterh
Messages: 108
Registered: November 2018
Location: Germany
Experienced Member
Hi I am just a beginner learning (I have practice in C and Object Pascal) and find your example interesting, so I tried it.

It shows zero for A and for B here with CLANGx64 and MSVC22x64. So it seems to work here.
(Windows10 x64, Upp build 16332)

So far I have read, the purpose of the initialization list is to initialize variables before any code is run and before the vtables are built.
This is why sometimes lists must be used, so the explanation in my book.

So I believe your example should work as intended.
I modified your example from reference to pointer and it runs equally well.
A pointer in theory can be initialized to an address where the target object does not yet exist (not recommended, but possible)
Now, a reference is essentially a constant self-dereferencing pointer that cannot be modified and must be initialized.
Here my pointer version:
#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> b_array;
	B() : A(b_array){
		Cout() << "Array Initial item count in B = " << b_array.GetCount() << "\n";
	}
};

CONSOLE_APP_MAIN{
	B b;
	Cout() <<"Fertig\n";
	Sleep(1000000);
}

[Updated on: Tue, 20 September 2022 15:45]

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 18:56:47 CEST 2024

Total time taken to generate the page: 0.01521 seconds