I have two variables in the Class primes i,p and they are assigned with values
in the constructor but they are not reflected in the method isprimes.

pr4.h
#include <fstream>
#include <iostream>
#include <cmath>
#include <string>


using namespace std;

#define MAX 65535

class primes {

typedef unsigned long ulong;
ulong pr[MAX];
ulong prm[MAX];

ulong p;
ulong i;
ulong maxp;

public:

primes();

primes(ulong p);

bool isprime();

inline void nextnumber();

inline void storeprime();

inline void showprime();

void saveprimes(const string fname);

bool next();

};



primes::primes(ulong p):maxp(p) { primes(); }

pr4.cpp
=======
#include "pr4.h"

int main()
{

primes prm(100000);

do {

if (prm.isprime()) 
        prm.storeprime();

prm.showprime();

} while(prm.next());

prm.saveprimes("output4.txt");
}

primes::primes()
{
cout << "primes" << endl;
i = 0;
pr[i++] = 2;
pr[i++] = 3;
pr[i++] = 5;
p = 7;
cout << "default constructor " << endl;
cout << this->i << endl;
cout << this->p << endl;
}

bool primes::isprime()
{
ulong cmax = ulong(sqrt(p));

if (cmax > pr[2]) {
for(int i =2; pr[i] && pr[i]<=cmax; i++)
        if (!(p%pr[i])) return false;
}
cout << "isprime" << i << " " << p <<  endl;
return true;
}

inline void primes::nextnumber() { 

static bool flag = true;

if (flag) 
        {p += 4; flag = false;}
else  
        {p += 2; flag = true;}

return; 
}

inline bool primes::next() {
nextnumber();
return (maxp > p);
}

inline void primes::storeprime() {
cout << i << " . " << p << endl;
pr[i++] = p;
cout << p << endl;
}

inline void primes::showprime() {
        if (!(i%1000)) cout << i << " " << pr[i-1] << endl;
}

void primes::saveprimes(const string fname)
{
fstream output;

output.open(fname.c_str());

for(int i =0; pr[i] && i<MAX; i++) output << i << " " << pr[i] << endl;

output.close();
}


BUILD
========
g++ -g -Wl,--enable-auto-import pr4.cpp lib.o -o t.exe

lib.cpp
=======
#include <iostream>
using namespace std;

unsigned long bit32()
{

unsigned long n = 0;

n--;

cout << n << endl;

n++;

cout << n << endl;

}

lib.h
======
unsigned long bit32();


-- 
           Summary: class members not getting assigned access thru another
                    method
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: k_suresh_babu at yahoo dot com
 GCC build triplet: g++ 4.3.2 on cygnus
  GCC host triplet: g++ 4.3.2  on cygnus
GCC target triplet: g++ 4.3.2 on cygnus


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42472

Reply via email to