The following code snippet, used to generate prime numbers, compile and runs as expected when debug starts, but it always seems to break the inker when building in Release mode:
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <iostream>
template<typename T> class PrimeGen {
struct Elim {
T p ;
T e ;
} ;
class Elim_cmp {
public:
bool operator()(const Elim& e1, const Elim& e2) { return e1.e > e2.e; }
} ;
std::vector<Elim> elim_heap ;
T last ;
public:
PrimeGen() {
Elim e0 = { 2, 4 } ;
elim_heap.reserve(1024) ;
elim_heap.push_back(e0) ;
last = 2 ;
}
T next() {
T n = last ;
bool prime;
do {
n ++ ;
prime = true ;
while(n == elim_heap.front().e) {
if(prime) prime = false ;
std::pop_heap(elim_heap.begin(), elim_heap.end(), Elim_cmp()) ;
Elim& elim = elim_heap.back() ;
elim.e = elim.p + n ;
std::push_heap(elim_heap.begin(), elim_heap.end(), Elim_cmp()) ;
}
} while(!prime) ;
Elim e = { n, 2*n } ;
elim_heap.push_back( e ) ;
std::push_heap(elim_heap.begin(), elim_heap.end(), Elim_cmp()) ;
return last = n ;
}
} ;
int main()
{
using namespace std ;
PrimeGen<unsigned int> pgen ;
for(int i=0; i<100; i++) {
cout << pgen.next() << endl ;
}
system("pause") ;
}
Can anyone understand why this is happening? Or did I come across one of those rare cases where the compiler is to blame, not the code?
The error I am getting is as follows:
error PRJ0002 : Error result -1073741819 returned from 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\mt.exe'.
If someone who runs Visual Studio takes time to try to create the code in release mode (I removed any external dependencies, so it should just be c & p), I would be very obliged.
. , mt.exe Release Hello World, . , . , .