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
This is what I keep getting in g++ when compiling in Solaris. The code compiles perfectly in VS2010. So I can't figure out what is going wrong.
Here are my class file's code 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;
}
Any help would be appreciated.
You don't seem to be compiling or linking data.cpp
. Try
g++ -o final.out final.cpp data.cpp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With