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

How should I implement a find() member function for this class?

Hello, I'm having trouble figuring out how to best explain my problem
but I hope I can make myself clear enough. Anyway, I'm doing an
assignment for school and in this one we're supposed to write a simple
"database" class. The interface of this database class supports adding
items, removing items, obtaining information about how many items are
stored etc. In the assignment the database is supposed to support only
storing items of a particular class (which we will write) but I was
thinking of doing a templated database class instead (our teacher
encourages us to go beyond the specification if our ideas are sound).

I haven't started writing any code yet but I'm having one problem:
The database interface has a find method that searches for an item based
on a parameter sent. The problem is that the find method is directly
tied to the class the database is supposed to store items of (the other
class we're supposed to write). If I make it templated so it can store
any kind of object, I need to write the find method in such a way that
the user can specify how searches should be implemented. How would I do
that? Some kind of function object?

I don't know if it's possible, but the ideal solution would be (I think)
to be able to search for items in the database in a number of ways but
having only one find function and not having to rewrite the database
class or the classes it stores when adding new ways of searching for
items. Say I want to store records and I have class representing a
record and I have my templated database. Then I would like to be able to
search for items matching, say, the artist of the record. Imagine I also
have another database, this one storing items representing cars. Now I
want to search for cars of a particular manufacturer and with lower
bound in bhp. And all this without having to change any classes
involved. So can I use functors here? Please advise. :)

If you didn't understand a thing I said, please give me an opportunity
to clarify.

- Payne
Sep 11 '08 #1
3 1489
On Sep 11, 6:55*am, Payne <inva...@invalid.invalidwrote:
Hello, I'm having trouble figuring out how to best explain my problem
but I hope I can make myself clear enough. Anyway, I'm doing an
assignment for school and in this one we're supposed to write a simple
"database" class. The interface of this database class supports adding
items, removing items, obtaining information about how many items are
stored etc. In the assignment the database is supposed to support only
storing items of a particular class (which we will write) but I was
thinking of doing a templated database class instead (our teacher
encourages us to go beyond the specification if our ideas are sound).
[snips]

Have you read about the standard container classes in
the standard library? You probably want to.
Socks
Sep 11 '08 #2
Puppet_Sock wrote:
On Sep 11, 6:55 am, Payne <inva...@invalid.invalidwrote:
>Hello, I'm having trouble figuring out how to best explain my problem
but I hope I can make myself clear enough. Anyway, I'm doing an
assignment for school and in this one we're supposed to write a simple
"database" class. The interface of this database class supports adding
items, removing items, obtaining information about how many items are
stored etc. In the assignment the database is supposed to support only
storing items of a particular class (which we will write) but I was
thinking of doing a templated database class instead (our teacher
encourages us to go beyond the specification if our ideas are sound).
[snips]

Have you read about the standard container classes in
the standard library? You probably want to.
Socks
Umm, what has that got to do with anything? I don't think I ever said
how the database class would be storing its data internally (it will be
using a standard container class fyi), because it was information not
needed for my question. The database classes has more things in its
interface, but I didn't mention them in my OP because those methods
weren't relevant to my question. Just using one of the standard
containers without a front-end isn't possible to meet the specifications
of the assignment, but the database class will interface with one
internally.
Also, this is an assignment, I can't just do what I like but I can give
feedback to teacher about things I don't like.
Anyway, judging from my own attempt and from the lack of serious
replies, I've decided to follow the specification on this one.

- Payne
Sep 11 '08 #3
On Sep 11, 1:23*pm, Payne <inva...@invalid.invalidwrote:
Puppet_Sock wrote:
On Sep 11, 6:55 am, Payne <inva...@invalid.invalidwrote:
Hello, I'm having trouble figuring out how to best explain my problem
but I hope I can make myself clear enough. Anyway, I'm doing an
assignment for school and in this one we're supposed to write a simple
"database" class. The interface of this database class supports adding
items, removing items, obtaining information about how many items are
stored etc. In the assignment the database is supposed to support only
storing items of a particular class (which we will write) but I was
thinking of doing a templated database class instead (our teacher
encourages us to go beyond the specification if our ideas are sound).
[snips]
Have you read about the standard container classes in
the standard library? You probably want to.
Socks

Umm, what has that got to do with anything?
[snip]

So, that would be a "no" then. Pretty much everything you
talked about is available through the standard containers.
Try reading about such things as algorithms, for example.
Socks
Sep 12 '08 #4

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

Similar topics

26
by: Oplec | last post by:
Hi, I am learning standard C++ as a hobby. The C++ Programming Language : Special Edition has been the principal source for my information. I read the entirety of the book and concluded that I...
2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
2
by: Kristoffer | last post by:
Hi! I have a general db class (a normal class, that contains the functions and subs to enable me to connect to my database) ok... but, HOW?? Do, I make use of this class in my asp.net...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
0
by: Armin Zingler | last post by:
Hi group, how can I have a base class member implement an interface member? Example: class a sub Member1 end sub end class
11
by: Manuel | last post by:
Hi, I need implement a map of member functions of some class. This map is formed by a string and a pointer to the member function. The problem is that the map need that the object saved are...
52
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
5
by: xz | last post by:
I am coding for this little class Date, which represents the date consisting of year, month and day. The header file is as follows: #ifndef DATE_H #define DATE_H class Date { static const...
20
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.