473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Initialization order

Dear all,
what is initialization order of members in VB?
Sometimes following assertion fails. Why?
Thank you in advance,
Boni
class A
inherits class B
dim pen as new system.drawing.pen(.)
sub new(.)
mybase.new(.)
debug.assert(not pen is nothing,"ops")
end sub
end class
Nov 21 '05 #1
4 1054
first the base class then the constructor , and then the members
so safest is to do this
sub new(.)
mybase.new(.)
dim pen as new system.drawing.pen(.)
debug.assert(not pen is nothing,"ops")
end sub
or

private pen as system.drawing.pen()
sub new(.)
mybase.new(.)
pen = new system.drawing.pen()
debug.assert(not pen is nothing,"ops")
end sub
ofcourse there are more possibility`s depending on your situation

michel posseth
"Boni" wrote:
Dear all,
what is initialization order of members in VB?
Sometimes following assertion fails. Why?
Thank you in advance,
Boni
class A
inherits class B
dim pen as new system.drawing.pen(.)
sub new(.)
mybase.new(.)
debug.assert(not pen is nothing,"ops")
end sub
end class

Nov 21 '05 #2
Hi,
I have a strange situation. I have a class with many constructors,
and a private member pen=new pen.
The call to draw function happens, when constructors is completely
finished.
But pen is nothing. If I initialize pen in constructor it does not happen.
Any ideas?
Thank you very much for your help.

"M. Posseth" <MP******@discussions.microsoft.com> schrieb im Newsbeitrag
news:D2**********************************@microsof t.com...
first the base class then the constructor , and then the members
so safest is to do this
sub new(.)
mybase.new(.)
dim pen as new system.drawing.pen(.)
debug.assert(not pen is nothing,"ops")
end sub
or

private pen as system.drawing.pen()
sub new(.)
mybase.new(.)
pen = new system.drawing.pen()
debug.assert(not pen is nothing,"ops")
end sub
ofcourse there are more possibility`s depending on your situation

michel posseth
"Boni" wrote:
Dear all,
what is initialization order of members in VB?
Sometimes following assertion fails. Why?
Thank you in advance,
Boni
class A
inherits class B
dim pen as new system.drawing.pen(.)
sub new(.)
mybase.new(.)
debug.assert(not pen is nothing,"ops")
end sub
end class

Nov 21 '05 #3
More code..

Friend Class A

Inherits B

Private m_pen As New System.Drawing.Pen(System.Drawing.Color.Beige) 'color
is dummy ! It is changed it time

Public Overrides Sub Draw()

Debug.Assert(Not Me.m_pen Is Nothing, "pen is nothing")

If Me.m_pen Is Nothing Then

Me.m_pen = New System.Drawing.Pen(System.Drawing.Color.Beige)

End If

End Sub

Public Sub New(ByVal id As intgere)

MyBase.New("aaaaa",id)

End Sub

Public Sub New()

MyBase.New()

End Sub

End Class
Nov 21 '05 #4
I am just decompiled the dll and now I am really confused. m_pen is created
not in all constructors!!!
I thought that if I initialize class member on the way like I did with pen,
it is declared in all constructors.
Please could somebody elaborate on this?
Public Sub New(....)

MyBase.New(..)

Return

End Sub

Public Sub New()

MyBase.New()

_m_pen = New Pen(Color.Beige)

Return

End Sub
"Boni" <oilia@nospam> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP12.phx.gbl...
More code..

Friend Class A

Inherits B

Private m_pen As New System.Drawing.Pen(System.Drawing.Color.Beige) 'color
is dummy ! It is changed it time

Public Overrides Sub Draw()

Debug.Assert(Not Me.m_pen Is Nothing, "pen is nothing")

If Me.m_pen Is Nothing Then

Me.m_pen = New System.Drawing.Pen(System.Drawing.Color.Beige)

End If

End Sub

Public Sub New(ByVal id As intgere)

MyBase.New("aaaaa",id)

End Sub

Public Sub New()

MyBase.New()

End Sub

End Class

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Massimiliano Alberti | last post by:
Now, in C++ you can do: struct X { int ia; int ib; }; class CL {
50
by: Charles Stapleton | last post by:
Given the folowing class class Ctest{ public: Ctest( int i, int j) :a(i) { b = j; } private: int a, b; } When creating an object of type Ctest, what advantage is there to setting
18
by: Makis Papapanagiotou | last post by:
Hello all, There is a strange case where a class Test is composed from three objects of other classes. i.e. class Test { public: Test(); private: Point x;
5
by: BigMan | last post by:
Does the standard define the order in which static members of a class are created and initialized?
6
by: anongroupaccount | last post by:
class CustomType { public: CustomType(){_i = 0;} CustomType(int i) : _i(i) {} private: int _i; }; class MyClass
8
by: lovecreatesbea... | last post by:
K&R 2, sec 2.4 says: If the variable in question is not automatic, the initialization is done once only, conceptually before the program starts executing, ... . "Non-automatic variables are...
11
by: asdf | last post by:
The oder of member initialization is the order in which the members are defined. So the following code is problematic: class X{ int i; int j; public: X(int val):j(val),i(j){}
2
by: Dennis Jones | last post by:
Hello, I have a class that will eventually look something like this: class TTableHolder { private: boost::scoped_ptr<TSessionFSession; boost::shared_ptr<TTableFTable;
10
by: n.torrey.pines | last post by:
Are global variables (and const's) guaranteed to be initialized before static class members (and methods) ? const int x = 19907; int get_x() { return x; } // another compilation unit: ...
20
by: JohnQ | last post by:
The way I understand the startup of a C++ program is: A.) The stuff that happens before the entry point. B.) The stuff that happens between the entry point and the calling of main(). C.)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.