473,396 Members | 1,712 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,396 software developers and data experts.

Writie classes of some algorithms

van
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!
Jul 22 '05 #1
2 1229
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

Jul 22 '05 #2
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
Jul 22 '05 #3

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

Similar topics

4
by: PHPkemon | last post by:
Hi there, A few weeks ago I made a post and got an answer which seemed very logical. Here's part of the post: PHPkemon wrote: > I think I've figured out how to do the main things like...
9
by: Pierre Barbier de Reuille | last post by:
Ok, I first want to stress that I looked through the newsgroups archives (on Google) for an answer to my question, but I didn't find it. It's about the interface of the set classes as defined in...
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
8
by: Jef Driesen | last post by:
I'm implementing some image processing algorithms in C++. I created a class called 'image' (see declaration below), that will take care of the memory allocations and some basic (mathematical)...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
3
by: ricky_casson | last post by:
I'm attempting to create a managed C++ class from some an already existing application that I have however some of the classes allow private access via the 'friend' keyword and i've heard that this...
21
by: T.A. | last post by:
I understand why it is not safe to inherit from STL containers, but I have found (in SGI STL documentation) that for example bidirectional_iterator class can be used to create your own iterator...
53
by: Vicent Giner | last post by:
Hello. I am new to Python. It seems a very interesting language to me. Its simplicity is very attractive. However, it is usually said that Python is not a compiled but interpreted programming...
1
by: Robert Blass | last post by:
I am looking to get my feet wet with encryption. When I say encryption program I am talking about something to get me off to a quick start. Something very simple, far less than the 40+ bit...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.