[Bug c++/42472] New: class members not getting assigned access thru another method

2009-12-22 Thread k_suresh_babu at yahoo dot com
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 
#include 
#include 
#include 


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(10);

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
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



[Bug c++/42472] class members not getting assigned access thru another method

2009-12-24 Thread k_suresh_babu at yahoo dot com


--- Comment #2 from k_suresh_babu at yahoo dot com  2009-12-25 02:43 ---
Subject: Re:  class members not getting assigned access thru another method

Hi,

So a constructor can't call another method if that is the case then it is ok. 
You can close the issue.

regards,
sureshbk.

--- On Wed, 12/23/09, redi at gcc dot gnu dot org 
wrote:

> From: redi at gcc dot gnu dot org 
> Subject: [Bug c++/42472] class members not getting assigned access thru 
> another method
> To: k_suresh_b...@yahoo.com
> Date: Wednesday, December 23, 2009, 5:09 AM
> 
> 
> --- Comment #1 from redi at gcc dot gnu dot org 
> 2009-12-23 11:09 ---
> C++ is not java, you cannot delegate to another constructor
> like this:
> 
> primes::primes(ulong p):maxp(p) { primes(); }
> 
> That creates a temporary object of type primes, it does not
> call the
> constructor.
> 
> Therefore primes::i and primes::p are not initialised by
> the primes(long)
> constructor.
> 
> 
> -- 
> 
> redi at gcc dot gnu dot org changed:
> 
>            What 
>   |Removed           
>          |Added
> 
>          
>    Status|UNCONFIRMED     
>            |RESOLVED
>          Resolution| 
>                
>           |INVALID
>            
> Version|unknown           
>          |4.3.2
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42472
> 
> --- You are receiving this mail because: ---
> You reported the bug, or are watching the reporter.
> 


-- 


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



[Bug c++/42472] class members not getting assigned access thru another method

2010-02-03 Thread k_suresh_babu at yahoo dot com


--- Comment #4 from k_suresh_babu at yahoo dot com  2010-02-04 07:07 ---
Subject: Re:  class members not getting assigned access thru another method

palo,

thank you for the clarification. You can close the bug.

regards,
sureshbk.

--- On Fri, 12/25/09, paolo dot carlini at oracle dot com
 wrote:

> From: paolo dot carlini at oracle dot com 
> Subject: [Bug c++/42472] class members not getting assigned access thru 
> another method
> To: k_suresh_b...@yahoo.com
> Date: Friday, December 25, 2009, 3:50 AM
> 
> 
> --- Comment #3 from paolo dot carlini at oracle dot
> com  2009-12-25 09:50 ---
> Yes, in C++03 (C++0x will be different), a constructor
> cannot call *another
> constructor*.
> 
> 
> -- 
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42472
> 
> --- You are receiving this mail because: ---
> You reported the bug, or are watching the reporter.
> 


-- 


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