R
rlwebbnafex
Hello,
I have never used generic programming so I need a little help for an
idea on what I can do.
I have defined a lot of classes like the following. The classes are
all pretty much the same, they just represent data structures that I
need to use later. I create an vector of each of these data structures
later. It is just a record-keeping system. Anyhow, is there a way to
create a generic structure and define the few member functions I have?
For example, the copy constructor always simply copies those few
variables I have. The Check() function always just sees if the object
matches the outside object. The problem is the number and type of
those simple data types that I am checking, eg. bioSourceNum and name.
Because of those of I have to define all of the functions on all of
the classes. and later, the functions on the vectors that contain all
of these objects.
class Protein
{
public:
int bioSourceNum;
int unificationXrefNum;
string name;
string type;
bool isWritten;
Protein();
Protein(int, int, string, string, bool);
Protein(const Protein&);
int Check(int a, int b, string c, string d);
Protein& operator =(const Protein&);
};
class Complex
{
public:
int sequenceParticipantNum1;
int sequenceParticipantNum2;
string name;
bool isWritten;
Complex();
Complex(int, int, string, bool);
Complex(const Complex&);
int Check(int a, int b, string c);
Complex& operator =(const Complex&);
};
I have never used generic programming so I need a little help for an
idea on what I can do.
I have defined a lot of classes like the following. The classes are
all pretty much the same, they just represent data structures that I
need to use later. I create an vector of each of these data structures
later. It is just a record-keeping system. Anyhow, is there a way to
create a generic structure and define the few member functions I have?
For example, the copy constructor always simply copies those few
variables I have. The Check() function always just sees if the object
matches the outside object. The problem is the number and type of
those simple data types that I am checking, eg. bioSourceNum and name.
Because of those of I have to define all of the functions on all of
the classes. and later, the functions on the vectors that contain all
of these objects.
class Protein
{
public:
int bioSourceNum;
int unificationXrefNum;
string name;
string type;
bool isWritten;
Protein();
Protein(int, int, string, string, bool);
Protein(const Protein&);
int Check(int a, int b, string c, string d);
Protein& operator =(const Protein&);
};
class Complex
{
public:
int sequenceParticipantNum1;
int sequenceParticipantNum2;
string name;
bool isWritten;
Complex();
Complex(int, int, string, bool);
Complex(const Complex&);
int Check(int a, int b, string c);
Complex& operator =(const Complex&);
};