2012-04-29 2 views
5
 
aludra.usc.edu(25): g++ -o final.out final.cpp 
Undefined      first referenced 
symbol        in file 
data::Get_Networth()    /var/tmp//ccUz9c59.o 
data::Set_Networth(double)   /var/tmp//ccUz9c59.o 
data::Get_Heightfeet()    /var/tmp//ccUz9c59.o 
data::Get_Lettergpa()    /var/tmp//ccUz9c59.o 
data::Set_Weight(int)    /var/tmp//ccUz9c59.o 
data::Get_Weight()     /var/tmp//ccUz9c59.o 
data::Get_Major()     /var/tmp//ccUz9c59.o 
data::Set_Gpa(double)    /var/tmp//ccUz9c59.o 
data::Get_GPA()      /var/tmp//ccUz9c59.o 
data::Set_Age(int)     /var/tmp//ccUz9c59.o 
data::Get_Age()      /var/tmp//ccUz9c59.o 
data::Set_Major(std::basic_string, std::allocator    >)/var/tmp//ccUz9c59.o 
data::Set_Data(std::basic_string, std::allocator >,  int, int, int, double, std::basic_string, std::allocator >, double)/var/tmp//ccUz9c59.o 
data::Get_Heightfeetremainder()  /var/tmp//ccUz9c59.o 
data::Set_Heightinches(int)   /var/tmp//ccUz9c59.o 
data::data()      /var/tmp//ccUz9c59.o 
data::Get_Name()     /var/tmp//ccUz9c59.o 
data::Get_Heightinches()   /var/tmp//ccUz9c59.o 
ld: fatal: Symbol referencing errors. No output written to final.out 
collect2: ld returned 1 exit status 

이것은 솔라리스에서 컴파일 할 때 g ++에서 계속 유지됩니다. 코드가 VS2010에서 완벽하게 컴파일됩니다. 그래서 나는 무엇이 잘못되었는지 알 수 없다. 여기 g ++에서 컴파일 할 때 심볼 참조 오류가있는 이유는 무엇입니까?

내 클래스 파일의 코드 data.h 있습니다

#include <string> 


using namespace std; 
class data{ 
private: 
string name; 
int age; 
int heightinches, heightfeet ,heightfeetremainder; 
int weight; 
double gpa; 
char lettergpa; 
string major; 
double networth; 


public: 
//constructors 
data(); 
//service functions 
void Calc_heightfeet(); 
void Calc_lettergpa(); 
//Getter/Accessor functions 
string Get_Name(); 
int Get_Age(); 
int Get_Heightinches(); 
int Get_Heightfeet(); 
int Get_Heightfeetremainder(); 
int Get_Weight(); 
double Get_GPA(); 
char Get_Lettergpa(); 
string Get_Major(); 
double Get_Networth(); 
//Setter/modifier functions 
void Set_Data(string ,int , int ,int , double,string,double); 
void Set_Age(int); 
void Set_Heightinches(int); 
void Set_Weight(int); 
void Set_Major(string); 
void Set_Gpa(double); 
void Set_Networth(double); 
}; 

data.cpp : 어떤 도움을 주시면 감사하겠습니다

#include "data.h" 
using namespace std; 


//constructors 
data::data(){;} 
//service functions 
void data::Calc_heightfeet() 
{ 
    heightfeet= heightinches/12; 
    heightfeetremainder= heightinches%12; 
} 
void data::Calc_lettergpa() 
{ 
    if (gpa > 3.5) 
      lettergpa= 'A'; 
    else if (gpa > 2.5) 
      lettergpa= 'B'; 
    else if (gpa > 1.5) 
      lettergpa= 'C'; 
    else if (gpa > .5) 
      lettergpa= 'D'; 
    else 
      lettergpa= 'F'; 
} 
//Getter/Accessor functions 
string data::Get_Name() 
{ 
    return name; 
} 
int data::Get_Age() 
{ 
    return age; 
} 
int data::Get_Heightinches() 
{ 
    return heightinches; 
} 
int data::Get_Heightfeet() 
{ 
    return heightfeet; 
} 
int data::Get_Heightfeetremainder() 
{ 
    return heightfeetremainder; 
} 
int data::Get_Weight() 
{ 
    return weight; 
} 
double data::Get_GPA() 
{ 
    return gpa; 
} 
char data::Get_Lettergpa() 
{ 
    return lettergpa; 
} 
string data::Get_Major() 
{ 
    return major; 
} 
double data::Get_Networth() 
{ 
    return networth; 
} 

//Setter/modifier functions 
void data::Set_Data(string n,int a, int h,int w, double g,string m,double net) 
{ 
    name=n; 
    age=a; 
    heightinches=h; 
    weight=w; 
    major=m; 
    networth=net; 
    gpa=g; 
    Calc_heightfeet(); 
    Calc_lettergpa(); 
} 
void data::Set_Age(int a) 
{ 
    age=a; 
} 
void data::Set_Heightinches(int h) 
{ 
    heightinches=h; 
    Calc_heightfeet(); 
} 
void data::Set_Weight(int w) 
{ 
    weight=w; 
} 
void data::Set_Major(string m) 
{ 
    major=m; 
} 
void data::Set_Gpa(double g) 
{ 
    gpa=g; 
    Calc_lettergpa(); 
} 
void data::Set_Networth(double net) 
{ 
    networth=net; 
} 

.

답변

7

data.cpp을 컴파일하거나 링크하는 것 같지 않습니다. 시도해보십시오.

g++ -o final.out final.cpp data.cpp 
+0

예! 고맙습니다! : facepalm : – luca992

+0

@ user1363742 얼굴을 감추기 전에 프로그램을 컴파일하는 데 사용한 명령과 모든 결과물을 게시하는 것에 대한 신뢰를 얻으십시오. 바로 문제를 발견하는 데 필요한 것입니다. –

+0

@ user1363742 : 귀하가 좋아하거나 유용하다고 생각하는 답변을 ** 확인하여 평판을 높이십시오. –

관련 문제