[CSC 315] For those using C++ Classes

Andrew J. Pounds pounds_aj at mercer.edu
Sun Oct 30 12:44:41 EDT 2016


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...



|#include "sysincludes.h" #include "namespaces.h" #ifndef CLUSTER_HEADER 
#define CLUSTER_HEADER class Cluster { /* Basic Class to hold Particle 
information */ public: Cluster(); vector<int> particles; void 
updateCount(); int get_number_of_particles(){updateCount(); return 
number_of_particles;}; private: int number_of_particles; }; #endif |||

|and the Cluster.cc file (that gets compiled) includes the header file 
from above contains...|

|||
|

|#include "sysincludes.h" #include "Cluster.h" #ifndef CLUSTER #define 
CLUSTER Cluster :: Cluster() { /* Default Constructor */ 
number_of_particles = 0.0; } void Cluster :: updateCount () { 
number_of_particles = particles.size(); } #endif |



||



-- 
Andrew J. Pounds, Ph.D.  (pounds_aj at mercer.edu)
Professor of Chemistry and Computer Science
Mercer University,  Macon, GA 31207   (478) 301-5627
http://faculty.mercer.edu/pounds_aj

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://theochem.mercer.edu/pipermail/csc315/attachments/20161030/30216958/attachment.html>


More information about the csc315 mailing list