I'm somewhat new to programming and am continually having this undefined reference error to all of my functions... can someone tell me what I'm doing wrong? Code is below (sorry for some of the weird documentation, my prof is extremely specific about his requirements for our programs).
/tmp/ccbpfCwv.o: In function `main':
runStudType.cxx:(.text+0xe5): undefined reference to `StudType::StudType()'
runStudType.cxx:(.text+0x2b2): undefined reference to `StudType::ReadData(std::basic_ifstream<char, std::char_traits<char> >&, StudType&)'
runStudType.cxx:(.text+0x2c1): undefined reference to `StudType::FindAvg(StudType&)'
runStudType.cxx:(.text+0x2e9): undefined reference to `StudType::PrintData(std::basic_ofstream<char, std::char_traits<char> >&, StudType)'
runStudType.cxx:(.text+0x2fd): undefined reference to `StudType::ReadData(std::basic_ifstream<char, std::char_traits<char> >&, StudType&)'
collect2: ld returned 1 exit status
void StudType::StudType()
//*******************************************************************
// Purpose: This constructor initializes the input data
// Input: none
// Pre: class is declared ok
// Output: none
// Post: Data is given initial value
// Note: none
//*******************************************************************
{
studId = 000;
exam1 = 0;
exam2 = 0;
exam3 = 0;
avg = 0;
}
void StudType::StudType(int studIdVal, float exam1Val, float exam2Val, float exam3Val)
//*************************************************************************************
// Purpose: This constructor initializes the input data
// Input: studIdVal, exam1Val, exam2Val, exam3Val
// Pre: data has value
// Output: none
// Post: Data is given initial value
// Note: none
//**************************************************************************************
{
studId = studIdVal;
exam1 = exam1Val;
exam2 = exam2Val;
exam3 = exam3Val;
}
void StudType::ReadData(ifstream& inFile, StudType& stud)
//*****************************************************************************
// Purpose: This function reads data from inFile and stores it in the object
// Input: inFile
// Pre: inFile is open and ok
// Output: stud
// Post: Data is stored in stud from inFile
// Note: none
//*****************************************************************************
{
inFile >> studId >> exam1 >> exam2 >> exam3;
}
void StudType::FindAvg(StudType& stud)
//*******************************************************************
// Purpose: This function finds the average of three exam scores
// Input: stud
// Pre: stud is declared and has value
// Output: stud
// Post: Average is stored in stud
// Note: none
//*******************************************************************
{
avg = (exam1 + exam2 + exam3) / 3;
}
void StudType::PrintData(ofstream& outFile, StudType stud)
//*******************************************************************
// Purpose: This function prints the data from stud to the outFile
// Input: stud
// Pre: outFile is open and ok, stud has value
// Output: outFile
// Post: Data is printed to the outFile
// Note: none
//*******************************************************************
{
outFile << studId << setw(5) << exam1 << setw(10) << exam2 << setw(10)
<< exam3 << setw(10 << avg << endl;
}
Without more information on the error itself, there's very little we can do to help. The error log might be cryptic, but it contains vital information to finding the problem with your code. Rather than summarizing it like you did in your title, I suggest you take a good long look at it and try to decypher it. It's the only way you'll learn to read them!
A quick look at your code makes me believe that the problem resides in StudType.cpp (or .cxx? Weird extension, but okay.): constructors don't have a return type! The "void" return type makes the compiler believe that there's a function StudType::StudType(), which obviously doesn't exist!
Added in the error message, sorry i forgot it originally. But I tried removing the voids from the implementation file and got the same error unfortunately.
I'll do that next time, sorry it's my first time posting here :) But that's so strange, I'm still getting the error! Any thoughts on what my problem could be? I tried changing the extensions to cpp, I'm not sure why my instructor wanted cxx. Still no luck...
It's the exact same as what was posted. And like I said before, I'm new to programming and not sure what programs are most used. My school uses PuTTY, not sure if you've heard of it. I really appreciate all the help though!
Here's the code exactly like I have it running on my IDE. Try copy-pasting it to a new project. If that doesn't work on your IDE, there's something wrong there, I think.
(By the way, make sure the filenames match the #include statement.)