multiple definition of 'xxxx'

Hi all,

I have been trying to build/ compile this program but i keep encountering this error message:

build/Debug/GNU-Linux-x86/MissionPlan.o: In function `LocationData':
/home/teocl5/NetBeansProjects/TeoChoonLong_4153480_Assn1/LocationData.cpp:8: multiple definition of `LocationData::LocationData()'
build/Debug/GNU-Linux-x86/LocationData.o:/home/teocl5/NetBeansProjects/TeoChoonLong_4153480_Assn1/LocationData.cpp:8: first defined here

In LocationData.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef LOCATIONDATA_H
#define	LOCATIONDATA_H


using namespace std;

class LocationData
{

    public:
        LocationData();
        LocationData(string ST, int NOELP, int NOELM, float APD, float APMD);
    private:
        string sunType;
        int noOfEarthLikePlanets;
        int noOfEarthLikeMoons;
        float aveParticulateDensity;
        float avePlasmaDensity;

};

#endif	 


In LocationData.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <cstdlib>
#include <iostream>
#include <cstring>
#include "LocationData.h"

using namespace std;

LocationData::LocationData()
{
    sunType = "";
    noOfEarthLikePlanets = 0;
    noOfEarthLikeMoons = 0;
    aveParticulateDensity = 0.0;
    avePlasmaDensity = 0.0;
}

LocationData:: LocationData(string ST, int NOELP, int NOELM, float APD, float APMD)
{
    sunType = ST;
    noOfEarthLikePlanets = NOELP;
    noOfEarthLikeMoons = NOELM;
    aveParticulateDensity = APD;
    avePlasmaDensity = APMD;
}


Your help will be greatly appreciated! thanks!
As the error message tells you, the error is in MissionPlan.cpp. You probably included the source file instead of the header.
Also, use the initialization list for member initializations and never use using namespace std; in a header.
Pass strings and similar types as a constant reference.
Last edited on
Hi athar! Thank you for the prompt reply! May I ask what u meant by initialization list?
Topic archived. No new replies allowed.