Often times, it helps to copy your work into another project, and reduce all extraneous functionality while still keeping the error that you're experiencing. This can help keep things as a digestible size.
In my case, I'm just going to show a working, but simple, example. Note that this is very much so contrived, just to show you how it looks syntactically.
Since you're using pointers, you need to be aware of who OWNS the pointer. In my example, I am making the Individual OWN the chromosome. I have the individual responsible for creating and destroying the chromosome. I hope that makes sense; I don't know if it does, seeing as I don't know much about biology at a chromosomal level...
Chromosome.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#ifndef CHROMOSOME_H
#define CHROMOSOME_H
class Individual; // declaring that "Individual" is, in fact, a class.
// This is needed to DECLARE a pointer of type Individual
class Chromosome {
public:
Chromosome(Individual* sequence);
Individual* getSequence(); // NOTICE: Not int* (like in your code)
private:
// A Chromosome contains a pointer to an Individual.
Individual* sequence;
};
#endif // INDIVIDUAL_H
|
Chromosome.cpp
1 2 3 4 5 6 7 8 9 10 11
|
#include "Chromosome.h"
Chromosome::Chromosome(Individual* sequence)
{
this->sequence = sequence;
}
Individual* Chromosome::getSequence()
{
return sequence;
}
|
Individual.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#ifndef INDIVIDUAL_H
#define INDIVIDUAL_H
class Chromosome; // declaring that "Chromosome" is, in fact, a class.
class Individual {
public:
Individual();
~Individual();
Chromosome* getChromosome();
private:
// An Individual contains a pointer to Chromosome (going by your example).
Chromosome* chromosome;
};
#endif // INDIVIDUAL_H
|
Individual.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include "Individual.h"
#include "Chromosome.h" // because we need to use actual Chromosome objects here, presumably.
Individual::Individual()
{
chromosome = new Chromosome(this); // again, just an example. Not necessarily best practice here.
}
Individual::~Individual()
{
delete chromosome;
}
Chromosome* Individual::getChromosome()
{
return chromosome;
}
|
main.cpp
1 2 3 4 5 6 7 8 9 10 11
|
#include "Individual.h"
#include "Chromosome.h"
int main()
{
Individual seq;
Chromosome chromo(&seq);
Individual* seq_ptr = chromo.getSequence(); // just doing some operation...
}
|
Compile with:
g++ -Wall Chromosome.cpp Individual.cpp main.cpp -o out |
(Or however you do it through your favorite IDE)
(Note: I just went with .cpp out of habit, .cc is also a valid extension, the compiler doesn't care)
Study this code and see how it all connects. Then, make a copy of your project (so that you don't destroy the original), and simplify it while still keeping the errors that you have.