Writie classes of some algorithms

Discussion in 'C++' started by van, Aug 1, 2004.

  1. van

    van Guest

    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!
     
    van, Aug 1, 2004
    #1
    1. Advertising

  2. van

    JKop Guest

    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
     
    JKop, Aug 1, 2004
    #2
    1. Advertising

  3. 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
     
    Victor Bazarov, Aug 2, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas
    Replies:
    0
    Views:
    509
    Andreas
    Dec 2, 2003
  2. abhinav

    encryption algorithms

    abhinav, Dec 26, 2004, in forum: VHDL
    Replies:
    2
    Views:
    646
  3. Melanie Nasic
    Replies:
    19
    Views:
    3,038
    Thomas Rudloff
    Jan 1, 2006
  4. Soenke
    Replies:
    0
    Views:
    565
    Soenke
    Dec 28, 2005
  5. David

    Pythonicity of some algorithms

    David, May 10, 2008, in forum: Python
    Replies:
    2
    Views:
    296
Loading...

Share This Page