Problem using functions in classes

I am currently facing error where the compiler shows me this

locationData.cpp 6 :error no void locationData::setSunType member function declared in class locationData.

However i have declared the classes in the header file but it still doesn`t solve it.

below are the snippets of my code.

locationData.cpp

#include "locationData.h"




void locationData::setSunType(string sun)
{
sunType=sun;

}


locationData.h
#ifndef LOCATIONDATA_H


#include<iostream>
#include<string>


#define LOCATIONDATA_H

using namespace std;

class locationData
{
private:


string sunType;
string dummy;
int noOfEarthLikePlanets;
int noOfEarthLikeMoons;
float aveParticulateDensity;
float avePlasmaDensity;

public:
void setSunType(string);


};

#endif

main.cpp
#include <iostream>
#include <string>
#include "locationData.h"


using namespace std;



void showProgram()
{
cout<<"Welcome to Mission Plan program!"<<endl<<

"1)Input statistical data."<<endl<<
"2)Compute civ. index value (for all records)"<<endl<<
"3)Print top 5 exploration destinations."<<endl<<
"4)Print total travel distance."<<endl;



}

int main()
{
locationData data;
string sunT;
int xCord,yCord,noOfEarthPlanet,noOfEarthMoon;
int choice;
float aveParticulateDensity;
float avePlasmaDensity;
showProgram();
cout<<"Please select your choice :";
cin>>choice;


switch(choice)
{
case 1 : cout<<"Input statistical data"<<endl;


cout<<"Please enter x-cordinate:";
cin>>xCord;
cout<<"Please enter y-cordinate:";
cin>>yCord;
cout<<"Please enter sun type: TYPE:";
cin>>sunT;
data.setSunType(sunT);
//data.getSunType(sunT);
cout<<"Please enter no. of earth-like planets:";
cin>>noOfEarthPlanet;
//data.getNoOfEarthLikePlanets(noOfEarthPlanet);
//data.setNoOfEarthLikePlanets(noOfEarthPlanet);
cout<<"Please enter no. of earth-like moons:";
cin>>noOfEarthMoon;
//data.getNoOfEarthLikeMoon(noOfEarthMoon);
//data.setNoOfEarthLikeMoon(noOfEarthMoon);
cout<<"Please enter ave. particulate density (%-tage):";
cin>>aveParticulateDensity;
// data.setAveParticulateDensity(aveParticulateDensity);
//data.getAveParticulateDensity(aveParticulateDensity);
cout<<"Please enter ave. plasma density (%-tage):";
cin>>avePlasmaDensity;
//data.getAvePlasmaDensity(avePlasmaDensity);
//data.setAvePlasmaDensity(avePlasmaDensity);



cout<<"Record succesfully stored. Going back to main menu."<<endl;

break;

default: cout<<"Invalid choice, please re-enter your choice."<<endl;

}


return 0;

}

may i know what is wrong with the code. I have been trying to debug it for hours.

Edit: i am using an ubuntu developer environment.
Edit: problem has been solved, however i would like to enquire. Why does a locationData.h.gch file appear?
Last edited on
Code looks valid to me. Tried testing a similar class in VS and it worked fine. Not sure why it's throwing that error out there.
Hi hutch, the problem was because i had another locationData.h.gch in the same directory. I removed it and it worked fine. I have no idea why that file appeared as i had no impression of creating it.
Ah, there we go then.

The gch file is a precompiled header file that your compiler has produced.
i see, why does this file appear?
I have seen .gch files being created when I press the compile button while viewing a header file in Geany. Maybe you did something similar with your IDE.
A few compilers do it. It's a precompiled header file that saves on compilation times. Sometimes, libraries are written as huge header files that are included rather than linking them at runtime. So if you include these huge headers, you often recompile them needlessly every time you build.

Some compilers will create these precompiled headers that'll get linked into the build, rather than doing a fresh compile of the header each time.

Edit: Here you go - http://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html
Last edited on
Topic archived. No new replies allowed.