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 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.
.... } 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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,...
|
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");
|
by: Antti Granqvist |
last post by:
Hello!
I have following object relations:
Competition 1--* Category 1--* Course
1
|
|
*
Course
|
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> { ...
|
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...
|
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...
|
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
|
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...
|
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;
|
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...
|
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: 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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |