I am getting the error in xcode Undefined symbols for architecture x86_64: “InputStream::Set()”, referenced from: Average(InputStream&) in Average2-12ad49.o “InputStream::Get() const”, referenced from: Average(InputStream&) in Average2-12ad49.o ld: symbol(s) not found for architecture x86_64 Is this somehow related to g++’s version?
Average2.cpp
#include "InputStream.h" #include <iostream> using namespace std; bool Average(InputStream& stream) { int count; double avr = 0; for(count = 0; stream.Set(); ++count) { avr += stream.Get(); } if(count == 0) { return false; } avr /= count; cout << "The average is " << avr << endl; return true; } int main() { while(true) { InputStream stream; if(! Average(stream)) { break; } } }
InputStream.h
#ifndef INPUTSTREAM_H_ #define INPUTSTREAM_H_ class InputStream { public: double Get() const; bool Set(); private: double m_n; }; #endif
InputStream.cpp
#include "InputStream.h" #include <iostream> using namespace std; double Inputstream::Get() const { return m_n; } bool InputStream::Set() { cin >> m_n; return m_n >= 0; }