main.cpp: (.text + 0x190): undefined reference to 'stddev::computeAverage(std::string)'
main.cpp: (.text + 0x2a9): undefined reference to 'stddev::computeStdDev(std::string)'
I'm fairly new to C++. Do I need to do something additional to call functions that belong to another class? Have I made "Java" assumptions? Anything you can do to help will be appreciated. The lines that are calling those functions are lines 34 and 44.
The functions in stddev.cpp are global functions, not member functions. It'd be better to get rid of the class stddev, since it doesn't contain any data.
Could you give me a quick explanation on the difference between global and member functions? I'm inclined to keep stddev, if only because I will be reusing the code throughout the semester.
I would still be able to - I'm calling that my last resort if I can't get this figured out. I just want to have the code in it's own little package, rather than integrated into my main.
Based on advice from other people, I've added stddev:: to the functions in stddev.cpp, but this hasn't solved the problem.
// #include <stddev.h>
#include "stddev.h" // use "" for your own headers
#include <sstream>
double stddev::computeAverage( std::string sequence )
{
int sum = 0 ;
std::istringstream numbers(sequence);
int currentNum = 0;
// this construct is canonical in C++
while( numbers >> currentNum ) // for each number read from the stream
{
// validate range
// ...
// if valid, add to sum
}
return sum ;
}
// ...