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

STL set (compilartion error) how to resolve this

Hi,
I want to create a set of cells (where it can be ints or doubles ).
The equatily condition is a.x==b.x and a.y==b.y.

I tried compiling this and it failed. Can someone help me.

#include<set>
#include<cstdio>
#include<iostream>
using namespace std;

struct cell {
int x,y;
};
cell a;

bool myeq(const cell &a,const cell &b)
{
if(a.x==b.x && a.y==b.y)
return true;
return false;
}

int main()
{
set <cell,myeqs;

s.insert(a);
return 0;
}

Jul 4 '06 #1
3 1305
Geo

te********@gmail.com wrote:
Hi,
I want to create a set of cells (where it can be ints or doubles ).
The equatily condition is a.x==b.x and a.y==b.y.

I tried compiling this and it failed. Can someone help me.

#include<set>
#include<cstdio>
#include<iostream>
using namespace std;

struct cell {
int x,y;
};
cell a;

bool myeq(const cell &a,const cell &b)
{
if(a.x==b.x && a.y==b.y)
return true;
return false;
}

int main()
{
set <cell,myeqs;

s.insert(a);
return 0;
}
In what way did it 'fail to compile', since you have provided no
output, does that mean you computer exploded as you trried to compile
it ?

Jul 4 '06 #2

Geo wrote:
te********@gmail.com wrote:
Hi,
I want to create a set of cells (where it can be ints or doubles ).
The equatily condition is a.x==b.x and a.y==b.y.

I tried compiling this and it failed. Can someone help me.

#include<set>
#include<cstdio>
#include<iostream>
using namespace std;

struct cell {
int x,y;
};
cell a;

bool myeq(const cell &a,const cell &b)
{
if(a.x==b.x && a.y==b.y)
return true;
return false;
}

int main()
{
set <cell,myeqs;

s.insert(a);
return 0;
}

In what way did it 'fail to compile', since you have provided no
output, does that mean you computer exploded as you trried to compile
it ?
$ g++ foo.cpp
foo.cpp: In function `int main()':
foo.cpp:22: error: type/value mismatch at argument 2 in template
parameter list
for `template<class _Key, class _Compare, class _Allocclass std::set'
foo.cpp:22: error: expected a type, got `myeq'
foo.cpp:22: error: invalid type in declaration before ';' token
foo.cpp:24: error: request for member `insert' in `s', which is of
non-class type `int'
$

Jul 4 '06 #3
te********@gmail.com wrote:
Hi,
I want to create a set of cells (where it can be ints or doubles ).
The equatily condition is a.x==b.x and a.y==b.y.

I tried compiling this and it failed. Can someone help me.

#include<set>
#include<cstdio>
#include<iostream>
using namespace std;

struct cell {
int x,y;
};
cell a;

bool myeq(const cell &a,const cell &b)
{
if(a.x==b.x && a.y==b.y)
return true;
return false;
}

int main()
{
set <cell,myeqs;

s.insert(a);
return 0;
}
You've got two separate problems. Firstly, set requires a strict weak
ordering function, not an equality function. So you need:

bool myless(const cell &a,const cell &b)
{
return a.x<b.x || (a.x==b.x && a.y<b.y);
}

Next, the second template parameter of set is a type, not a function. So
either make myless into a type:

struct myless
{
bool operator()(const cell &a,const cell &b) const
{
return a.x<b.x || (a.x==b.x && a.y<b.y);
}
};

or use the function:

set<cell,bool(*)(const cell &a,const cell &b)s(myless);

I think you'll prefer the former. The final option is to define
operator< for cell.

Tom
Jul 4 '06 #4

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

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
1
by: yanwan | last post by:
I met this problem in executing a c++ project in visual studio. Does anyone have suggestions to resolve "error lnk 2001"? --------------------Configuration: reconstruction - Win32...
1
by: Tony Johansson | last post by:
Hello! I get compile error when compiling using the command javac from the command terminal window(CMD). I have just two classes which are called HelloWorld.java and Slask.java. I have both...
2
by: Coy Howe | last post by:
I have an access program I would like to distribute to many computers that do not have access. I have Office Developer and have used the Packaging Wizard to put together the software, however when...
1
by: Raed Sawalha | last post by:
We Handling our ASPX error in global.ascx and log the error in XML file with following informatio: Date URL Error Message Stack Trace Exception Type are there more information can be...
0
by: Mike Eaton | last post by:
Hi all, I'm getting an error when I attempt to run the Dns.Resolve(hostName) method: No more results can be returned by WSALookupServiceNext I am able to ping the hostname I'm attempting...
0
by: roger23 | last post by:
I get this error C:\Program Files\MSBuild\Microsoft\WebDeployment\v8.0\Microsoft.WebDeployment.targets(526,9): error MSB6006: "aspnet_compiler.exe" exited with code 1. at the end of my build...
1
by: BSand0764 | last post by:
I'm getting an error that I can't seem to resolve. When I compile the Functor related logic in a test program, the files compile and execute properly (see Listing #1). However, when I...
3
by: Sindhu Rani | last post by:
i hav created 3 classes in 3 different files. am gettin an error durin compilation. wat shud i do??? C:\s\source>javac -d ..\classes devtestdrive.java devtestdrive.java:5: cannot resolve symbol...
0
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,...
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...
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
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,...

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.