Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Writie classes of some algorithms

Reply
Thread Tools

Writie classes of some algorithms

 
 
van
Guest
Posts: n/a
 
      08-01-2004
Writing classes of some algorithms, some parameters needs to be passed into
the classes, the actual algorithms are contained in member functions of
classes.

What I am thinking is having some ordinary member variables as parameters
for algorithms, and member functions as "static". Since "static" member
function cannot access ordinary member variables, it is logic to make the
latter as "static" as well.

I am very curious about how you'd like to design such kind of classes.

Thanks for your sharing!


 
Reply With Quote
 
 
 
 
JKop
Guest
Posts: n/a
 
      08-01-2004
van posted:

> Writing classes of some algorithms, some parameters needs to be passed
> into the classes, the actual algorithms are contained in member
> functions of classes.
>
> What I am thinking is having some ordinary member variables as
> parameters for algorithms, and member functions as "static".


Why are you going with "static" if you have ordinary member variables?

> Since "static" member function cannot access ordinary member variables, it
> is logic to make the latter as "static" as well.
>
> I am very curious about how you'd like to design such kind of classes.
>
> Thanks for your sharing!


Okkayyyyy... very little information, but I'll give it a go.

Let's say that the parameters for the algorithm are:

a string
a number
a boolean

So far we have:

class Ranger
{
public:

const char* name;
int id;
bool is_alive;
};



Now with some algorithmic functions:


class Ranger
{
public:

const char* name;
int id;
bool is_alive:

int WhatYearWasBorn();
unsigned char AmountOfChildren();
bool WillBeAliveTomorrow();
};

int main()
{
Ranger frankie;

frankie.name = "Francis Duffy";
frankie.id = 2256;
frankie.is_alive = true;

//Ofcourse you'd have a constructor for the above

//Now here comes algorithmic functions that work
//with the member data:

frankie.WhatYearWasBorn();
frankie.AmountOfChildren();
frankie.WillBeAliveTomorrow();


};


Did that clear anything up at all?


-JKop

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      08-02-2004
van wrote:
> Writing classes of some algorithms, some parameters needs to be passed into
> the classes, the actual algorithms are contained in member functions of
> classes.
>
> What I am thinking is having some ordinary member variables as parameters
> for algorithms, and member functions as "static". Since "static" member
> function cannot access ordinary member variables, it is logic to make the
> latter as "static" as well.
>
> I am very curious about how you'd like to design such kind of classes.


The usual approach to doing what you've described (IIUIC) is to write
a class that will be constructed with the necessary arguments and then
its overloaded operator() (operator function call) should implement the
actual algorithm. Pass additional arguments to the operator() as needed.

Victor
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pythonicity of some algorithms David Python 2 05-10-2008 11:53 AM
real-time compression algorithms on fpga Melanie Nasic VHDL 19 01-01-2006 06:00 AM
Routines and algorithms for DRM/SBR Soenke VHDL 0 12-28-2005 10:02 AM
encryption algorithms abhinav VHDL 2 12-29-2004 12:08 PM
Map n algorithms to m functional units Andreas VHDL 0 12-02-2003 02:34 PM



Advertisments