473,831 Members | 2,347 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1519
On Sep 11, 6:55*am, Payne <inva...@invali d.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...@invali d.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...@invali d.invalidwrote:
Puppet_Sock wrote:
On Sep 11, 6:55 am, Payne <inva...@invali d.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
3163
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 had done myself a disservice by having not attempted and completed the exercises. I intend to rectify that. My current routine is to read a chapter and then attempt every exercise problem, and I find that this process is leading to a greater...
2
3643
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 support. (first i compiled them with g++3.x. ERR means compiler will bark, otherwise it does accept it. Then the Comeau C/C++ 4.3.3 comes)
2
1529
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 application... I need to contact it from my codebehind page... but, I contact my codebehind page with the src= tag, so it compiles when I contact the webpage, and not before...
5
19604
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 having a problem in the calling program. I searched online and found suggestions that I return an Array instead so I modified my code (below) to return an Array instead of an ArrayList. Now I get the message when I try to run just my webservice...
0
935
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
1835
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 the same type. So what type to specify in the declaration of the map? map<std::string,void *¿?
52
20923
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 'UselessJunkForDissassembly.IInvocableInternals.OperationValidate(string)' C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
5
8137
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 int daysInMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
20
3107
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 like 65% of the time of the second routine. Yet both do the same thing. However, the second one seems better in terms of the way the code is written since it helps encapsulate the transformation in the inner loop better making it easier to read,...
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10777
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10494
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10534
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10207
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9317
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5619
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.