473,378 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

static objet and how to see its value

Hi
i'm new to c++ i have the class num for big unsigned numbers
it seems work ok until now and i want extend the numbers to big-signed
and big-float

typedef struct{
unsigned len;
unsigned* n;
}num_;

/* big integer unsigned */
class num{
friend int operator==(const num& a, const num& b);
.............................
friend num& operator+(const num& a, const num& b);
.............................
friend num& operator+(const num& a, unsigned b);
.............................
public:
num();
num(double);
num(num&r );
.............
private:
num_ numer;
unsigned lm;
}

// i have write a the definition of class snum
// big integer signed
class snum{
public:
snum();
snum(double);
snum(num&r );
.............
private:
num sn;
int sign;
}

// i have written a definition of class fnum
// big float
class fnum{
public:
fnum();
fnum(double);
fnum(num&r );
.............
private:
snum fn;
unsigned fdigit;
}

Do you see some better way to build the classes fnum and snum by class
num?(and why)

then i have a little problem i have something like
static fnum z[10];
i have the need to write
num g("444555");
z[1].nf.ns=g
or something like
z[1].nf.ns.numer.n[0]=7;
or
z[1].nf.ns.numer.len =7;

*in a function member of num*

and suppose something like

snum& operator+(snum& a, snum& b);
{int j=index();
if(a.sign==1)
{if(b.sign==1)
{z[j].nf.ns.sign= 1; z[j].nf.ns.n= a.ns.n + b.ns.n;}
else if(a.ns.n > b.ns.n)
{z[j].nf.ns.sign= 1; z[j].nf.ns.n= a.ns.n - b.ns.n;}
else {z[j].nf.ns.sign=-1; z[j].nf.ns.n= b.ns.n - a.ns.n;}
}
else {if(b.sign==-1)
{z[j].nf.ns.sign=-1; z[j].nf.ns.n= a.ns.n + b.ns.n;}
else if(a.ns.n > b.ns.n) // b.sign=+1
{z[j].nf.ns.sign=-1; z[j].nf.ns.n= a.ns.n - b.ns.n;}
else {z[j].nf.ns.sign= 1; z[j].nf.ns.n= b.ns.n - a.ns.n;}
}
return z[j].nf.ns
}

How to do it? (compiler says i can not enter from fnum to snum)
Do you see some error?
Thank you

Jul 23 '05 #1
2 1373
On 4 Jul 2005 10:26:45 -0700, as***********@yahoo.com wrote:

yes i have a troll hart
it seems i like the c++ classes but the remain of the language is in
the wrong direction

i have change; i don't know if it work if don't work i use brute force
(assembly)

typedef struct{
unsigned len;
unsigned* n;
}num_;

/* big integer unsigned */
class num{
public:
friend int operator==(const num& a, const num& b);
.............................
friend num& operator+(const num& a, const num& b);
.............................
friend num& operator+(const num& a, unsigned b);
.............................
num();
num(double);
num(num&r );
.............
private:
num_ numer;
unsigned mem;
unsigned fdigit;
}

// i have write a the definition of class snum
// big integer signed
class snum{
public:
snum();
snum(double);
snum(num&r );
.............
private:
num_ numer;
unsigned mem;
unsigned fdigit;
}

// i have written a definition of class fnum
// big float
class fnum{
public:
fnum();
fnum(double);
fnum(num&r );
.............
private:
num_ numer;
unsigned mem;
unsigned fdigit;
}

static fnum z[10];
static snum *zz = (snum*) z;
static num *zzz= (num*) z;

num g("444555");
zzz[1]=g
or something like
zzz[1].numer.n[0]=7;
or
zzz[1].numer.len =7;
*in a function member of num*

and suppose something like
snum& operator+(const snum& a, const snum& b);
{int j=index();
if(a.sign>0)
{if(b.sign>0)
{zz[j].sign= 1; sum_(&zz[j].n, &a.numer, &b.numer);}
in a function of class snum
etc

Jul 23 '05 #2
On 5 Jul 2005 10:37:46 -0700, as***********@yahoo.com wrote:
yes i have a troll hart
it seems i like the c++ classes but the remain of the language is in
the wrong direction. Seems that c++ is too much complex (easy thing are
the point of arrive)
and the key word for class seems to me is not 'hide' but 'organize'

i have change;

typedef struct{
unsigned len;
unsigned* n;
}num_;

/* big integer unsigned */
class num{
public:
friend int operator==(const num& a, const num& b);
.............................
friend num& operator+(const num& a, const num& b);
.............................
friend num& operator+(const num& a, unsigned b);
.............................
num();
num(double);
num(num&r );
.............
public:
num_ numer;
unsigned mem;
unsigned fdigit;
}

// i have write a the definition of class snum
// big integer signed
class snum{
public:
snum();
snum(double);
snum(num&r );
public:
num sn;
}

// i have written a definition of class fnum
// big float
class fnum{
public:
fnum();
fnum(double);
fnum(num&r );
public:
num fn;
}

static fnum z[10];
static snum *zz = (snum*) z;
static num *zzz= (num*) z;

num g("444555");
zzz[1]=g
or something like
zzz[1].numer.n[0]=7;
or
zzz[1].numer.len =7;
*in a function member of num*

and suppose something like
snum& operator+(const snum& a, const snum& b);
{int j=index();
if(a.sn.fdigit==0)
{if(b.sn.fdigit==0)
{zz[j].sn.fdigit=0;
sum_( &zz[j].sn.numer, &a.sn.numer, &b.sn.numer); };
in a function of class snum
etc
all is accessible but the it is difficult to do errors with names
becuause they are long in a hierarchy
but why your help is "void"

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: crjjrc | last post by:
Hi, I've got a base class and some derived classes that look something like this: class Base { public: int getType() { return type; } private: static const int type = 0; };
3
by: Steve Folly | last post by:
Hi, I had a problem in my code recently which turned out to be the 'the "static initialization order fiasco"' problem (<http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12>) The FAQ...
9
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've...
16
by: subramanian100in | last post by:
Consider the following program: #include <iostream> using namespace std; class Test { static Test t; static Test init_Test( ) { return t; }
8
by: jayaramganapathy | last post by:
Hello friends, I have a map like std::map< std::string , std::map<std::string, std::string>* EpPropCache::propertyCache ; (This is a static instance and taken from *.cpp file) As you can see...
5
by: Michael Oswald | last post by:
Hello all, I'm working on a project where I came across some situations, where the GUI library works with normal C callbacks. The code has been implemented by many people, so I came across...
5
by: Gernot Frisch | last post by:
// - in my xy.cpp file -- template <const int Ttex, const int Tcol, const int Tlight, int TzBuffer> struct MyFragmentShader { static const int varying_count = Ttex*2 + Tcol*3 + Tlight; }; ...
15
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
1
by: flowstudioLA | last post by:
I have a template class object that I use as a mesaging queue between threads. I use it as a static object that I initialize like so: foo.h class foo{ static LFQueue<const char*,100lfqMyQueue;...
5
by: chgans | last post by:
Hi all, I'm having difficulties with some template static member, especially when this member is a template instance, for example: ---- template<typename T> class BaseT { public: static...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.