I'm trying to use an object in two different multiset containers, each
with it's own sort method. For the most frequently used, I overrode
the operator< method in the class, and for the second I wrote a method
LocationSort(). I can't seem to arrive upon the correct syntax for
defining a multiset that will use LocationSort.
multiset<DotObject,DotObject::LocationSort> mySet;
fails.
Is there a correct way to do this while keeping LocationSort inside of
my class? I know I could wrap it in a separate structure and pass in
the structure name, but would prefer to keep it inside the class code
for ease-of-maintenance reasons.
Thanks.
Dale 5 2405
"Dale Marchand" <da***********@gmail.com> schrieb im Newsbeitrag
news:11*********************@g43g2000cwa.googlegro ups.com... I'm trying to use an object in two different multiset containers, each with it's own sort method. For the most frequently used, I overrode the operator< method in the class, and for the second I wrote a method LocationSort(). I can't seem to arrive upon the correct syntax for defining a multiset that will use LocationSort.
multiset<DotObject,DotObject::LocationSort> mySet;
fails.
Is there a correct way to do this while keeping LocationSort inside of my class? I know I could wrap it in a separate structure and pass in the structure name, but would prefer to keep it inside the class code for ease-of-maintenance reasons.
Try to make LocationSort a static member function (with two parameters) of
DotObject. If that doesn't work (I didn't try it), you can still make a
separate struct/class. Such a struct can be defined inside the DotObject
class, like
class DotObject
{
public:
struct LocationSort
{
bool operator()(DotObject const& lhs, DotObject const& rhs)
const
{
return ...
}
};
...
};
HTH
Heinz
Thanks. I just hit upon option 2 about 10 seconds prior to reading
your post (no, really I did!). It works fine....I'd just think there'd
be a simpler, more elegent way.
I'd prefer to stay away from static members, just because I've got a
bunch of threads running and prefer to stay away from the synch hassles
that static's bring.
Thanks.
Dale
On 3 Jan 2006 13:11:24 -0800 in comp.lang.c++, "Dale Marchand"
<da***********@gmail.com> wrote, I'd just think there'd be a simpler, more elegent way. I'd prefer to stay away from static members
The compare function is called with two arguments, and not as a
member function. If you want to use a member function, you can wrap
it in a std::mem_fun() adapter. See Stroustrup chap. 18.4.4.2
just because I've got a bunch of threads running and prefer to stay away from the synch hassles that static's bring.
No reason a static member _function_ (without any local static
variables etc.) should cause a problem.
I read your reference on mem_fun, and it looks like I'm limited to 1
arg member functions at most. Since the Compare function requires 2
args, I don't see how I can use that, unless I'm missing something?
On 4 Jan 2006 10:31:43 -0800 in comp.lang.c++, "Dale Marchand"
<da***********@gmail.com> wrote, I read your reference on mem_fun, and it looks like I'm limited to 1 arg member functions at most. Since the Compare function requires 2 args, I don't see how I can use that, unless I'm missing something?
What you are missing is that in a member function, the object upon
which the function is invoked is equivalent to another argument.
Foo.memfun(Bar) and nonmemfun(Foo, Bar) have effectively the same
number of arguments. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John MacIntyre |
last post by:
Hi,
I have a page with a series of child pages loaded into an iframe. When I
move from page to page, I store an object containing the child's control
data in a variable on the main page, then...
|
by: Alex Vinokur |
last post by:
Here is some function that detects if a vector contains only different elements
bool vector_contains_only_different_elements (const vector<int>& v)
{
for (int i = 0; i < v.size(); i++)
{
if...
|
by: Arthur J. O'Dwyer |
last post by:
I'm seeing a bug at the moment that I can't track down. It's
part of a moderately large program, but here is a small program
that exhibits the bug on gcc. (The program code follows at the
bottom...
|
by: John Harrison |
last post by:
If you insert equal values into a multiset is it specified what order they
will have in the multiset. For instance, what should be the output of this
program, is it defined?
#include <set>...
|
by: Simon Harvey |
last post by:
Hi,
In my application I get lots of different sorts of information from
databases. As such, a lot of information is stored in DataSets and DataTable
objects.
Up until now, I have been passing...
|
by: Stuart Hilditch |
last post by:
Hi all,
I am hoping that someone with some experience developing nTier apps can give
me some advice here.
I am writing an nTier web app that began with a Data Access Layer (DAL),
Business...
|
by: =?iso-8859-1?q?Jo=E3o_Correia?= |
last post by:
class CScore
{
public:
int L;
int C;
CScore(int l, int c)
{
L = l;
C = c;
|
by: neil.johnston |
last post by:
I have a cut down example program that uses multiset to order some
data. The data arrives from various sources and has a time stamp, data
with identical timestamps can arrive and due to fifo's and...
|
by: orzeech |
last post by:
Hi everyone!
I have a following problem:
#include<iostream>
#include<set>
using namespace std;
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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...
| |