2013-10-05 2 views
1

BaseClass : location 데이터를 상속받은 SubClass : PointTwoD가 있습니다. 이 오류가 발생합니다 : 내 주요 기능에서 PointTwoD에 대한 정의되지 않은 참조, 누군가가 내게 설명 할 수 이유는 ?? Sub Class에 대한 정의되지 않은 참조

기본 클래스 locationdata.h

#include <string> 
#include <iostream> 

using namespace std; 

class locationdata 
{ 
    public: 
    locationdata(); //default constructor 
    locationdata(string,int,int,float,float); //constructor 

//setter 
void set_sunType(string); 
void set_noOfEarthLikePlanets(int); 
void set_noOfEarthLikeMoons(int); 
void set_aveParticulateDensity(float); 
void set_avePlasmaDensity(float); 

//getter 
string get_sunType(); 
int get_noOfEarthLikePlanets(); 
int get_noOfEarthLikeMoons(); 
float get_aveParticulateDensity(); 
float get_avePlasmaDensity(); 


float computeCivIndex(); 
friend class PointTwoD; 

     private: 

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

}; 

기본 클래스 locationdata.cpp

#include <iostream> 
#include "locationdata.h" 
using namespace std; 

locationdata::locationdata() 
{ 
    this->sunType = ""; 
    this->noOfEarthLikePlanets=0; 
    this->noOfEarthLikeMoons=0; 
    this->aveParticulateDensity=0; 
    this->avePlasmaDensity=0; 

} 

locationdata::locationdata(string sunType , int noOfEarthLikePlanets , 
         int noOfEarthLikeMoons , float aveParticulateDensity , 
         float avePlasmaDensity) 

{ 
    this->sunType = sunType; 
this->noOfEarthLikePlanets = noOfEarthLikePlanets; 
this->noOfEarthLikeMoons = noOfEarthLikeMoons; 
this->aveParticulateDensity = aveParticulateDensity; 
this->avePlasmaDensity = avePlasmaDensity; 

} 

void locationdata::set_sunType(string sunType) 
{ 
    this->sunType = sunType; 

} 

void locationdata::set_noOfEarthLikePlanets(int noOfEarthLikePlanets) 
{ 

this->noOfEarthLikePlanets = noOfEarthLikePlanets; 
} 

void locationdata::set_noOfEarthLikeMoons(int noOfEarthLikeMoons) 
{ 
this->noOfEarthLikeMoons = noOfEarthLikeMoons; 
} 

void locationdata:: set_aveParticulateDensity(float aveParticulateDensity) 
{ 
this->aveParticulateDensity = aveParticulateDensity; 

} 

void locationdata::set_avePlasmaDensity(float avePlasmaDensity) 
{ 
this->avePlasmaDensity = avePlasmaDensity; 
} 


string locationdata::get_sunType() 
{ 
return this->sunType; 
} 

int locationdata::get_noOfEarthLikePlanets() 
{ 
return this->noOfEarthLikePlanets; 
} 

int locationdata::get_noOfEarthLikeMoons() 
{ 
return this->noOfEarthLikeMoons; 
} 

float locationdata::get_aveParticulateDensity() 
{ 
return this->aveParticulateDensity; 
} 

float locationdata::get_avePlasmaDensity() 
{ 
return this->avePlasmaDensity; 

} 

float locationdata::computeCivIndex() 
{ 
string temp = this->get_sunType(); 
int sunTypePercent; 
float CivIndex ; 

if (temp == "Type O") 
{ 
sunTypePercent = 30; 
} 
else if (temp == "Type B") 
{ 
sunTypePercent = 45; 

} 
else if (temp == "Type A") 
{ 
sunTypePercent = 60; 

} 
else if (temp == "Type F") 
{ 
sunTypePercent = 75; 
} 
else if (temp =="Type G") 
{ 
sunTypePercent = 90; 
} 
else if (temp =="Type K") 
{ 
sunTypePercent = 80; 
} 
else if (temp =="Type M") 
{ 
sunTypePercent = 70; 
} 




      CivIndex=1.5; 

      return CivIndex; 
} 

하위 클래스 PointTwoD.h

#include <iostream> 
#include "locationdata.h" 

using namespace std; 

class PointTwoD:public locationdata 
{ 
    public: 
    PointTwoD(); 

    private: 
    int x; 
    int y; 
    float civIndex; 




}; 

하위 클래스 PointTwoD.cpp

#include "PointTwoD.h" 

PointTwoD::PointTwoD() 
{ 
    this ->x = 0; 
    this->y = 0; 

    this->set_sunType(""); 
    this->set_noOfEarthLikePlanets(0); 
    this->set_noOfEarthLikeMoons(0); 
    this->set_aveParticulateDensity(0); 
    this->set_avePlasmaDensity(0); 

} 
01,235

16,

당신이 (예., .cc 또는 .cpp 파일) 여러 소스 파일을 포함하는 프로젝트를 컴파일 할 때, 당신은 당신이 실행 파일을 만들 때 각 파일이 포함되어 있는지 확인해야

#include <iostream> 
#include "PointTwoD.h" 

using namespace std; 

int main() 
{ 
int choice; 
PointTwoD test; //undefined reference 
test.set_noOfEarthLikeMoons(10); // undefined reference 
cout<<test.get_noOfEarthLikeMoons() //undefined reference 
} 
+0

난 당신이 모두를 포함하지 않는 생각 당신이 컴파일 할 때 파일들. 어떻게 프로젝트를 컴파일하고 있습니까? – jxh

+0

@jxh quincy 2005를 사용하여이 파일을 컴파일 중입니다. 모든 파일을 같은 폴더에 넣습니다. – Computernerd

+0

그래, 어떻게 도와 줄 수 있는지 모르겠습니다. 프로젝트에 여러 소스 파일을 추가하는 방법에 대한 설명서를 읽어야합니다. – jxh

답변

1

주요 기능. 어떻게 그 달성하는 것은 (당신의 main()의 마지막 cout 문에 누락 된 ;를 추가 한 후) 컴파일러에 따라 다르지만 g++로, 내가 이런 짓을하고 잘 컴파일 :

g++ main.cpp locationdata.cpp PointTwoD.cpp 
관련 문제