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

std::map with user defined data

Hi,

I try to use map. My code is very easy, but there are some errors....
(by compiling). Plaese, could you say, what I do wrong..

struct less_array
{
bool operator()(const FArray p1, const FArray p2) const
{
return p1 < p2 ;
}
};

int main(){

....

map<const FArray, vector<FArray>, less_array> my_map;

const vector<FArray>& vert1 = .....getVert1(); // a vector of.
vector<FArray>::const_iterator vert = vert1.begin();

if(my_map.find(vert) == my_map.end()) // line 172 in code
cout<<"map is empty"<<endl;

my_map[vert]= new FArray(); // line 194 in code

.....
}

Compiler gets error-message because of my_map-find and my_map[vert].
Compiler message is:
....
FDualMarchingCubesAlgorithm.cc:176: error: no matching function for
call to `
std::map<const FArray, std::vector<FArray, std::allocator<FArray> >,
FDualMarchingCubesAlgorithm::less_array,
std::allocator<std::pair<const FArray,
std::vector<FArray, std::allocator<FArray> > > > >::find(
__gnu_cxx::__normal_iterator<const FArray*, std::vector<FArray,
std::allocator<FArray> > >&)'
/usr/include/g++/bits/stl_map.h:468: error: candidates are: typename
std::_Rb_tree<_Key, std::pair<const _Key, _Tp>,
std::_Select1st<std::pair<const _Key, _Tp> >, _Compare,
_Alloc>::iterator
std::map<_Key, _Tp, _Compare, _Alloc>::find(const _Key&) [with _Key
= const
FArray, _Tp = std::vector<FArray, std::allocator<FArray> >, _Compare
=
FDualMarchingCubesAlgorithm::eqpos, _Alloc =
std::allocator<std::pair<const
FArray, std::vector<FArray, std::allocator<FArray> > > >]
.....

DualMarchingCubesAlgorithm.cc:194: error: no match for 'operator[]' in
'
my_map[vert]'
......

thank you on advance!

Joana

Jan 17 '06 #1
2 2372
me*****************@yahoo.de wrote:
Hi,

I try to use map. My code is very easy, but there are some errors....
(by compiling). Plaese, could you say, what I do wrong..

struct less_array
{
bool operator()(const FArray p1, const FArray p2) const
{
return p1 < p2 ;
}
};
Not an error, but you should probably pass the arguments by reference to
ensure they are not unnecessarily copied. But then, you don't need the
whole struct, since the above is the default behavior for maps.
int main(){

...

map<const FArray, vector<FArray>, less_array> my_map;

const vector<FArray>& vert1 = .....getVert1(); // a vector of.
vector<FArray>::const_iterator vert = vert1.begin();

if(my_map.find(vert) == my_map.end()) // line 172 in code
vert is a const_iterator. Your map's key type is not such an iterator type,
so you can't use it as argument type for find(). You probably wanted:

if(my_map.find(*vert) == my_map.end())
cout<<"map is empty"<<endl;

my_map[vert]= new FArray(); // line 194 in code
The value type of your map is not FArray*, but std::vector<FArray>, so the
right side of your assignment needs to be of that type.
....
}


Jan 17 '06 #2

me*****************@yahoo.de wrote:

map<const FArray, vector<FArray>, less_array> my_map;

vector<FArray>::const_iterator vert = vert1.begin();

my_map[vert]= new FArray(); // line 194 in code

....
}


To answer just the question asked, it is invalid because vert is an
iterator, not an FArray. Also the RHS will not convert from FArray * to
vector< FArrray >

my_map[ *vert ] = vector< FArray > ( 1 );

will work albeit that I'm a bit questionable about your design.

Jan 17 '06 #3

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

Similar topics

5
by: Christopher | last post by:
I am having problems iterating through the sequence of objects stored in my std::map I want to call a function from the "value" object in the map. Here is my snippet: typedef std::map<SOCKET,...
24
by: Duane Hebert | last post by:
2 questions: Given a map defined as std::map<int,string> stringmap; //How do you access the data_type (string) via an iterator? std::string spoo("doh");
1
by: Antti Granqvist | last post by:
Hello! I have following object relations: Competition 1--* Category 1--* Course 1 | | * Course
1
by: Bob | last post by:
Hi, I'm trying to use a map with a string key, and a pointer to objects contained in a vector. I've wrapped this in a class like so: // cMap template<class T> class cMap : public cList<T> { ...
1
by: Saeed Amrollahi | last post by:
Dear All C++ Programmers Hello I am Saeed Amrollahi. I am a software engineer in Tehran Sewerage Company. I try to use std::map and map::find member function. I use Visual Studio .NET. my...
3
by: Dan Trowbridge | last post by:
Hi everyone, In my attempt to port code from VS 6.0 to VS.NET I had some code break along the way, mostly due to not adhereing closely to the C++ standard. This may be another instance but I...
13
by: kamaraj80 | last post by:
Hi I am using the std:: map as following. typedef struct _SeatRowCols { long nSeatRow; unsigned char ucSeatLetter; }SeatRowCols; typedef struct _NetData
7
by: Matthias Pfeifer | last post by:
Hi there, a std::map is build from std::pair elements where for a pair p p.first is called the key and p.second the value. Is there a way to keep the map sorted by the values? Ie is there a...
6
by: Juha Nieminen | last post by:
joseph cook wrote: Not always. By default, yes, but you can specify other comparators, eg: std::map<int, int, std::greaterreversedMap;
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
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...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.