<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to keywords-constructor</title><link>https://sourceforge.net/p/asil/wiki/keywords-constructor/</link><description>Recent changes to keywords-constructor</description><atom:link href="https://sourceforge.net/p/asil/wiki/keywords-constructor/feed" rel="self"/><language>en</language><lastBuildDate>Tue, 18 Feb 2014 10:30:05 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/asil/wiki/keywords-constructor/feed" rel="self" type="application/rss+xml"/><item><title>keywords-constructor modified by Will Pittenger</title><link>https://sourceforge.net/p/asil/wiki/keywords-constructor/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Used to declare a special type of procedure that resembles a &lt;strong&gt;&lt;a class="" href="/p/asil/wiki/keywords-function/"&gt;function&lt;/a&gt;&lt;/strong&gt; and initializes the type.  Constructors can either initialize an instance or the static data members.  Like functions, constructors can take any set of parameters and keywords needed.  Unlike functions, instance constructors always return a copy of the constructed type instance.  Static constructors always return nothing.  Furthermore, constructors can only be called with help from the &lt;strong&gt;&lt;a class="" href="../keywords-new"&gt;new&lt;/a&gt;&lt;/strong&gt; keyword.  Instance constructors can be public, protected, or private.  Private instance constructors can only be called by a &lt;strong&gt;&lt;a class="" href="../keywords-static"&gt;static&lt;/a&gt;&lt;/strong&gt; method or property in the same class.  Instance constructors can be overloaded as needed.  Static constructors never take any parameters.&lt;/p&gt;
&lt;h2 id="instance-constructors"&gt;Instance constructors&lt;/h2&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;public&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;protected&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;private&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;constructor&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;identifier&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;DeclarationSequence&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
  &lt;span class="err"&gt;'&lt;/span&gt; &lt;span class="n"&gt;Initialize&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;class&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;/DeclarationSequence/ must be as described in &lt;a class="" href="../Appendices-Terms-Declaration%20sequences"&gt;Declaration Sequences&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="static-constructors"&gt;Static constructors&lt;/h2&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="k"&gt;static&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;constructor&lt;/span&gt;\
  &lt;span class="err"&gt;'&lt;/span&gt; &lt;span class="n"&gt;Initialize&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="n"&gt;members&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="creating-an-instance"&gt;Creating an instance&lt;/h2&gt;
&lt;p&gt;As long as the type isn't &lt;strong&gt;&lt;a class="" href="/p/asil/wiki/keywords-abstract/"&gt;abstract&lt;/a&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;a class="" href="../keywords-static"&gt;static&lt;/a&gt;&lt;/strong&gt;, you can instantiate an instance with the syntax below which will call constructors for the type as needed.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;TypeName&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ParameterList&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;/TypeName/ must be the name of the type being instantiated and /ParameterList/ must be the parameters needed by that constructor along with any required keywords.  Please note this sample doesn't show what you do with the new instance.  You might also need to put the parameter list into parentheses depending on what else you are doing.  If you put the expression from the &lt;strong&gt;&lt;a class="" href="../keywords-new"&gt;new&lt;/a&gt;&lt;/strong&gt; keyword to through the parameter list, but no farther, you can use the &lt;strong&gt;&lt;a class="" href="../operators-member"&gt;.&lt;/a&gt;&lt;/strong&gt; operator to access the data members, methods, and properties in the new instance as shown below:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Test  &amp;quot;&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;TrimRight&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;(The String type was only used for that sample as no further declarations were needed for the sample.)&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Will Pittenger</dc:creator><pubDate>Tue, 18 Feb 2014 10:30:05 -0000</pubDate><guid>https://sourceforge.net8e1aeb7b45bedab170e4e3cd874ef361dbb3f9f7</guid></item></channel></rss>