-2

I know there are similar questions but none of these work in my case. Hi I cannot find why I have this issue. Here is my individual.h file:

#ifndef INDIVIDUAL_H
#define INDIVIDUAL_H

#include <vector>
#include <stdlib.h>
#include <time.h> 
#include <iostream>


using namespace std;

class Individual{
    private:
        vector<unsigned int> chromosome;
        unsigned int n_genes;
        unsigned int N_colours_used = 0;
        unsigned int fitness = 0;

    public:
        Individual(unsigned int ngenes){};

};

#endif

And this is my individual.cpp file:

#include "individual.h"


Individual :: Individual(unsigned int ngenes){
    cout << "something" << endl;
}

The error looks like this

src/individual.cpp:4:1: error: redefinition of ‘Individual::Individual(unsigned int)’
Individual :: Individual(unsigned int ngenes){
 ^
In file included from src/individual.cpp:1:0:
include/individual.h:24:13: note: ‘Individual::Individual(unsigned int)’ previously defined here
             Individual(unsigned int ngenes){};

I tried everything thats in stackoverflow but I still don't know how to solve this problem. Also
"#pragma once" does not work.

Juanjo
  • 79
  • 1
  • 8
  • Unrelated to your problem, but I suggest you take some time to read [What are the rules about using an underscore in a C++ identifier?](https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier) Then think about your macro `_INDIVIDUAL_H`. – Some programmer dude Nov 14 '17 at 19:01

1 Answers1

5
    Individual(unsigned int ngenes){};

As you can see you have { } after your function declaration, which is a definition of an empty body.

Then you are trying to redefine the body of the function in the .cpp file. Remove { }.

Jack
  • 131,802
  • 30
  • 241
  • 343