<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p><font face="serif">If you are one of those folks that has chosen
to use C++ classes, the standard way to segment those files is
to create a header containing the variables and definitions and
another file to contain the constructors and methods. For
example, in one of my codes that uses C++ classes I have a
cluster class to keep up with the various nanoparticle clusters
during a simulation. Here is the Cluster.h file...</font></p>
<p><font face="serif"><br>
</font></p>
<p><font face="serif"></font><br>
</p>
<pre><code class="language-h hljs "><span id="LC1" class="line"><span class="hljs-preprocessor">#<span class="hljs-keyword">include</span> "sysincludes.h"</span></span>
<span id="LC2" class="line"><span class="hljs-preprocessor">#<span class="hljs-keyword">include</span> "namespaces.h"</span></span>
<span id="LC3" class="line"></span>
<span id="LC4" class="line"><span class="hljs-preprocessor">#ifndef CLUSTER_HEADER</span></span>
<span id="LC5" class="line"><span class="hljs-preprocessor">#<span class="hljs-keyword">define</span> CLUSTER_HEADER</span></span>
<span id="LC6" class="line"></span>
<span id="LC7" class="line"><span class="hljs-keyword">class</span> Cluster {</span>
<span id="LC8" class="line"></span>
<span id="LC9" class="line"> <span class="hljs-comment">/* Basic Class to hold Particle information */</span></span>
<span id="LC10" class="line"> <span class="hljs-keyword">public</span>:</span>
<span id="LC11" class="line"> Cluster();</span>
<span id="LC12" class="line"> <span class="hljs-stl_container"><span class="hljs-built_in">vector</span><<span class="hljs-keyword">int</span>></span> particles;</span>
<span id="LC13" class="line"> <span class="hljs-keyword">void</span> updateCount();</span>
<span id="LC14" class="line"> <span class="hljs-keyword">int</span> get_number_of_particles(){updateCount(); <span class="hljs-keyword">return</span> number_of_particles;}; </span>
<span id="LC15" class="line"> <span class="hljs-keyword">private</span>:</span>
<span id="LC16" class="line"> <span class="hljs-keyword">int</span> number_of_particles; </span>
<span id="LC17" class="line">};</span>
<span id="LC18" class="line"></span>
<span id="LC19" class="line"><span class="hljs-preprocessor">#<span class="hljs-keyword">endif</span> </span></span>
</code><code class="language-h hljs "></code></pre>
<p><font face="Times New Roman, Times, serif"><code>and the
Cluster.cc file (that gets compiled) includes the header file
from above contains...</code></font></p>
<code></code><code><br>
</code><br>
<pre><code class="language-cc hljs cpp"><span id="LC2" class="line"><span class="hljs-preprocessor">#<span class="hljs-keyword">include</span> "sysincludes.h"</span></span>
<span id="LC3" class="line"><span class="hljs-preprocessor">#<span class="hljs-keyword">include</span> "Cluster.h"</span></span>
<span id="LC4" class="line"></span>
<span id="LC5" class="line"><span class="hljs-preprocessor">#ifndef CLUSTER </span></span>
<span id="LC6" class="line"><span class="hljs-preprocessor">#<span class="hljs-keyword">define</span> CLUSTER </span></span>
<span id="LC7" class="line"></span>
<span id="LC8" class="line"></span>
<span id="LC9" class="line">Cluster :: Cluster() {</span>
<span id="LC10" class="line"></span>
<span id="LC11" class="line"> <span class="hljs-comment">/* Default Constructor */</span></span>
<span id="LC12" class="line"></span>
<span id="LC13" class="line"> number_of_particles = <span class="hljs-number">0.0</span>;</span>
<span id="LC14" class="line">}</span>
<span id="LC15" class="line"></span>
<span id="LC16" class="line"><span class="hljs-keyword">void</span> Cluster :: updateCount () {</span>
<span id="LC17" class="line"></span>
<span id="LC18" class="line"> number_of_particles = particles.size(); </span>
<span id="LC19" class="line"></span>
<span id="LC20" class="line">} </span>
<span id="LC21" class="line"></span>
<span id="LC22" class="line"><span class="hljs-preprocessor">#<span class="hljs-keyword">endif</span></span></span>
</code></pre>
<br>
<br>
<pre><code class="language-h hljs "></code></pre>
<br>
<br>
<pre class="moz-signature" cols="72">--
Andrew J. Pounds, Ph.D. (<a class="moz-txt-link-abbreviated" href="mailto:pounds_aj@mercer.edu">pounds_aj@mercer.edu</a>)
Professor of Chemistry and Computer Science
Mercer University, Macon, GA 31207 (478) 301-5627
<a class="moz-txt-link-freetext" href="http://faculty.mercer.edu/pounds_aj">http://faculty.mercer.edu/pounds_aj</a>
</pre>
</body>
</html>