I'm newish to c++ and even newer to ubuntu
I tried linking and this is what I got:
g++ -o calculator *.o -lcrypt -lm
main.o: In function `main':
main.cpp: (.text+0x1ea): undefined reference to `SAMSErrorHandling::Initialize()'
main.cpp: (.text+0x2fa): undefined reference to `SAMSErrorHandling::HandleNotANumberError()'
main.cpp: (.text+0x322): undefined reference to `SAMSPrompt::UserWantsToContinueYOrN(char const*)'
collect2: ld returned 1 exit status
let it be noted I've never linked anything using command line
Dev-C++ used to magically do all that stuff for me.
Not sure what the problem is...
Someone reccomended I put "using namespace SAMSErrorHandling" in main.cpp but the error message remains the same
everything compiles fine, it's just putting these all together into something I can run that's giving me the probelm
here's main.cpp:
#include <iostream>
#include <stdexcept>
#include "PromptModule.h"
#include "ErrorHandlingModule.h"
using namespace std;
char GetOperator(void)
{
char theOperator;
cout << "Operator: ";
cin >> theOperator;
return theOperator;
}
float GetOperand(void)
{
float theOperand = 1;
cout << "The Operand: ";
cin >> theOperand;
return theOperand;
}
float Accumulate (const char theOperator,const float theOperand)
{
static float myAccumulator = 0; //Inititalize to 0 when the program starts
switch (theOperator)
{
case '+':
myAccumulator = myAccumulator + theOperand;
break;
case '-':
myAccumulator = myAccumulator - theOperand;
break;
case '*':
myAccumulator = myAccumulator * theOperand;
break;
case '/':
myAccumulator = myAccumulator / theOperand;
break;
default:
throw
runtime_error("Error - Invalid Operator");
};
return myAccumulator;
}
int main(int argc, char* argv[])
{
SAMSErrorHandling::Initialize();
do
{
try
{
char Operator = GetOperator();
float Operand = GetOperand();
cout << Accumulate(Operator,Operand) << endl;
}
catch (runtime_error RuntimeError)
{
SAMSErrorHandling::HandleRuntimeError(RuntimeError);
}
catch (...)
{
SAMSErrorHandling::HandleNotANumberError();
};
}
while (SAMSPrompt::UserWantsToContinueYOrN("More ?"));
return 0;
}
here are the two headers in case I messed those up:
#ifndef PromptModuleH
#define PromptModuleH
namespace SAMSPrompt
{
bool UserWantsToContinueYOrN (const char *theThingWeAreDoing);
}
#endif
and the second one:
#ifndef ErrorHandlingModuleH
#define ErrorHandlingModuleH
#include <stdexcept>
using namespace std;
namespace SAMSErrorHandling
{
void Initialize(void);
int HandleNotANumberError(void); //Returns error code
int HandleRuntimeError(runtime_error theRuntimeError);
}
#endif
thanks in advance.