I have three files: main.cpp, Euler.h, and Euler.cpp. In Euler.cpp, I have a function that calculates prime numbers using Euler's sieve:
In Euler.h, I have the forward declaration for the sieve:
And then in main.cpp, I have some code for testing my sieve function, through solving of one of Project Euler's problems:
But when trying to compile main.cpp, I am getting the following error:
What could be causing this?
Code:
vector<int> sieve(vector<int>& primelist, int i) { bool primes[i]; primes[0] = false; primes[1] = false; for (int j = 2; j < i; j++) primes[j] = true; for (int j = 2; j * j < i; j++) { if (primes[j]) { for (int k = j; k*j < i; k++) primes[k*j] = false; } } for (int k = 2; k < i; k++) { if (primes[k]) primelist.push_back(k); } }
Code:
#ifndef EULER_H #define EULER_H #include <vector> #include "Euler.cpp" vector<int> sieve(vector<int>& primelist, int i); #endif
Code:
#include <iostream> #include "Euler.h" using namespace std; bool isPrime(int check, const vector<int>& primes) { for (vector<int>::const_iterator it = primes.begin(); *it < check + 1; ++it) { if (*it == check) return true; } return false; } int main() { vector<int> primes; int max_co = 0; int max_co_sec = 0; int max = 0; int x; sieve(primes, 1000); for (int a = -999; a < 1000; a++) { for (int b = 0; b < 1000; b++) { cout << "a " << a << " b " << b << endl; x = 0; while (isPrime(x*x+a*x+b, primes)) x++; if (x > max) { max = x; max_co = a; max_co_sec = b; } } } cout << max_co * max_co_sec << endl; return 0; }
Code:
In file included from Euler.h:5, from main.cpp:2: Euler.cpp:1: error: expected constructor, destructor, or type conversion before ‘<’ token
Comment