Hi. I'm a Java programmer making the switch to C++. Could someone enlighten me as to what's going wrong here:
g++ -o fermat.cc main.cc
main.cc: In function `int main()':
main.cc:8: error: `Fermat' was not declared in this scope
main.cc:8: error: `f' was not declared in this scope
main.cc:8: error: `Fermat' is not a type
#include <iostream>
#include "fermat.h"
using namespace std;
int main() {
Fermat* f = new Fermat(81);
cout << "Is the number " << f->getNum() << " prime? ";
cout << f->isPrime() << endl;
return 0;
}
fermat.h
#define FERMATH
#ifndef FERMATH
#include <iostream>
#include <cmath>
using namespace std;
class Fermat {
private:
long prime p;
public:
Fermat();
Fermat(long num);
long getNum();
bool isPrime();
}
#endif
#define FERMATCC
#ifndef FERMATCC
#include "fermat.h"
#include <iostream>
#include <cmath>
Fermat::Fermat() {
// Do Nothing
}
Fermat::Fermat(long num) {
p = num;
}
bool Fermat::isPrime() {
// Will redo later. Probably doesn't work.
// Will also error if number is less than 10.
int a = p;
int pm1 = p - 1;
bool allPrime = true;
for(int i=0; i<10; i++) {
a--;
if(pow(a, pm1) % p != 1) {
allPrime = false;
}
}
return allPrime;
}
long Fermat::getNum() {
return p;
}
#endif