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

using templates and map

hey how is it goin,
i've got this problem - declared a template but it doesn't work
properly, here is the code:

53 std::map<Config, Config> seen;
54 Config new();
55 seen.insert(new, new);

i need to do it that way but the code brakes when i write the command
"seen.insert(new, new);"

i can assure you that everything else is working, just this - > i've
declared the template properly, cause i've used it in other parts of
the code, and i've also included the <map> library. by the way this is
the error, that i get - i also can't understand the error:

bash-2.05$ make
g++ -ggdb -c clock.cpp
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/bits/stl_tree.h:
In member function `void std::_Rb_tree<_Key, _Val, _KeyOfValue,
_Compare, _Alloc>::insert_unique(_II, _II) [with _InputIterator =
ClockConfig (*)(), _Key = ClockConfig, _Val = std::pair<const
ClockConfig, ClockConfig>, _KeyOfValue =
std::_Select1st<std::pair<const ClockConfig, ClockConfig> >, _Compare
= std::less<ClockConfig>, _Alloc = std::allocator<std::pair<const
ClockConfig, ClockConfig> >]':
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/bits/stl_map.h:397:
instantiated from `void std::map<_Key, _Tp, _Compare,
_Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator =
ClockConfig (*)(), _Key = ClockConfig, _Tp = ClockConfig, _Compare =
std::less<ClockConfig>, _Alloc = std::allocator<std::pair<const
ClockConfig, ClockConfig> >]'
Solver.cpp:55: instantiated from `void Solver<Config>::solve() [with
Config = ClockConfig]'
clock.cpp:60: instantiated from here
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/bits/stl_tree.h:993:
error: ISO C++ forbids incrementing a pointer of type `ClockConfig
(*)()'
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/bits/stl_tree.h:994:
error: no matching function for call to `std::_Rb_tree<ClockConfig,
std::pair<const ClockConfig, ClockConfig>,
std::_Select1st<std::pair<const ClockConfig, ClockConfig> >,
std::less<ClockConfig>, std::allocator<std::pair<const ClockConfig,
ClockConfig> > >::insert_unique(ClockConfig (&)())'
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/bits/stl_tree.h:862:
note: candidates are: std::pair<typename std::_Rb_tree<_Key, _Val,
_KeyOfValue, _Compare, _Alloc>::iterator, bool> std::_Rb_tree<_Key,
_Val, _KeyOfValue, _Compare, _Alloc>::insert_unique(const _Val&) [with
_Key = ClockConfig, _Val = std::pair<const ClockConfig, ClockConfig>,
_KeyOfValue = std::_Select1st<std::pair<const ClockConfig,
ClockConfig> >, _Compare = std::less<ClockConfig>, _Alloc =
std::allocator<std::pair<const ClockConfig, ClockConfig> >]
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/bits/stl_tree.h:888:
note: typename std::_Rb_tree<_Key, _Val, _KeyOfValue,
_Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue,
_Compare, _Alloc>::insert_unique(std::_Rb_tree_iterator<_Val >, const
_Val&) [with _Key = ClockConfig, _Val = std::pair<const ClockConfig,
ClockConfig>, _KeyOfValue = std::_Select1st<std::pair<const
ClockConfig, ClockConfig> >, _Compare = std::less<ClockConfig>, _Alloc
= std::allocator<std::pair<const ClockConfig, ClockConfig> >]
*** Error code 1
make: Fatal error: Command failed for target `clock.o'
any help will be really appreciated!!!!
thanks a lot!!!
Jul 22 '05 #1
7 2044
Stoian wrote:
hey how is it goin,
i've got this problem - declared a template but it doesn't work
properly, here is the code:

53 std::map<Config, Config> seen;
54 Config new();
This defines a function called new() that returns a Config (prolly not
what you want).
55 seen.insert(new, new);
Inserting a function ?

i need to do it that way but the code brakes when i write the command
"seen.insert(new, new);"

i can assure you that everything else is working, just this - > i've
declared the template properly, cause i've used it in other parts of
the code, and i've also included the <map> library. by the way this is
the error, that i get - i also can't understand the error:

error snipped ... basically is says.

You're trying to call ...
....::insert_unique(ClockConfig (&)())

But a :
....::insert_unique(const _Val&)

is the only candidate.
Jul 22 '05 #2
> 53 std::map<Config, Config> seen;
54 Config foo;
55 seen.insert(std::make_pair(foo, foo));


new - key word
Config foo() - declaration of function
Jul 22 '05 #3

"Stoian" <sp*****@yahoo.com> wrote in message
news:4a**************************@posting.google.c om...
hey how is it goin,
i've got this problem - declared a template but it doesn't work
properly, here is the code:

53 std::map<Config, Config> seen;
54 Config new();
55 seen.insert(new, new);

1) new is not a legal name for a variable.
2) don't put backets after the variable name, that makes it a function.
3) you have to make a pair to insert into a map

std::map<Config, Config> seen;
Config noo;
seen.insert(std::make_pair(noo, noo));

That should compile.

john
Jul 22 '05 #4
thanks a lot, i actually didn't notice when i writing these 3 lines
here, so i just put "new" and didn't realise (i didn't actually paste
the code). Ok i tried the make pair, and i still have errors, I'm not
that good with using templates, but i think that the problem is with
defining a comparator, probably the default one doesn't work with
templates, i don't know.
Here is what i did, and the error again:

50 Config temp;
51 std::map<Config, Config> seen;
52 seen.insert(std::make_pair(temp, temp));
bash-2.05$ make
g++ -ggdb -c change.cpp
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/
bits/stl_function.h: In member function `bool
std::less<_Tp>::operator()(const _
Tp&, const _Tp&) const [with _Tp = ChangeConfig]':
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/
bits/stl_tree.h:869: instantiated from `std::pair<typename
std::_Rb_tree<_Key,
_Val, _KeyOfValue, _Compare, _Alloc>::iterator, bool>
std::_Rb_tree<_Key, _Val,
_KeyOfValue, _Compare, _Alloc>::insert_unique(const _Val&) [with _Key
= ChangeC
onfig, _Val = std::pair<const ChangeConfig, ChangeConfig>, _KeyOfValue
= std::_S
elect1st<std::pair<const ChangeConfig, ChangeConfig> >, _Compare =
std::less<Cha
ngeConfig>, _Alloc = std::allocator<std::pair<const ChangeConfig,
ChangeConfig>
]' /usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/
bits/stl_map.h:360: instantiated from `std::pair<typename
std::_Rb_tree<_Key,
std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp>, _Compa

re, _Alloc>::iterator, bool> std::map<_Key, _Tp, _Compare,
_Alloc>::insert(const
std::pair<const _Key, _Tp>&) [with _Key = ChangeConfig, _Tp =
ChangeConfig, _Co
mpare = std::less<ChangeConfig>, _Alloc =
std::allocator<std::pair<const ChangeC
onfig, ChangeConfig> >]'
Solver.cpp:52: instantiated from `void Solver<Config>::solve() [with
Config =
ChangeConfig]'
change.cpp:64: instantiated from here
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/
bits/stl_function.h:227: error: no match for 'operator<' in '__x <
__y'
*** Error code 1
make: Fatal error: Command failed for target `change.o'
bash-2.05$
thanks again for your help
Jul 22 '05 #5
"Stoian" <sp*****@yahoo.com> wrote...
thanks a lot, i actually didn't notice when i writing these 3 lines
here, so i just put "new" and didn't realise (i didn't actually paste
the code). Ok i tried the make pair, and i still have errors, I'm not
that good with using templates, but i think that the problem is with
defining a comparator, probably the default one doesn't work with
templates, i don't know.
Here is what i did, and the error again:

50 Config temp;
51 std::map<Config, Config> seen;
52 seen.insert(std::make_pair(temp, temp));

[...]
bits/stl_function.h:227: error: no match for 'operator<' in '__x <
__y'
*** Error code 1


Does your 'Config' class have operator< defined for it or in it? If not,
you cannot use it as the key in a map unless you define your own special
comparison functor. If you know how to compare two 'Config' objects,
then defining operator< is probably easier than anything else.

Victor
Jul 22 '05 #6
You should define 'new' like this:

Config new;

rather than

Config new();

where the latter means 'define a funtion named new with void parameter list
and return Config'.

"Stoian" <sp*****@yahoo.com>
??????:4a**************************@posting.google .com...
hey how is it goin,
i've got this problem - declared a template but it doesn't work
properly, here is the code:

53 std::map<Config, Config> seen;
54 Config new();
55 seen.insert(new, new);

i need to do it that way but the code brakes when i write the command
"seen.insert(new, new);"

i can assure you that everything else is working, just this - > i've
declared the template properly, cause i've used it in other parts of
the code, and i've also included the <map> library. by the way this is
the error, that i get - i also can't understand the error:

bash-2.05$ make
g++ -ggdb -c clock.cpp
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/bits/stl_tree.h:
In member function `void std::_Rb_tree<_Key, _Val, _KeyOfValue,
_Compare, _Alloc>::insert_unique(_II, _II) [with _InputIterator =
ClockConfig (*)(), _Key = ClockConfig, _Val = std::pair<const
ClockConfig, ClockConfig>, _KeyOfValue =
std::_Select1st<std::pair<const ClockConfig, ClockConfig> >, _Compare
= std::less<ClockConfig>, _Alloc = std::allocator<std::pair<const
ClockConfig, ClockConfig> >]':
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/bits/stl_map.h:397:
instantiated from `void std::map<_Key, _Tp, _Compare,
_Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator =
ClockConfig (*)(), _Key = ClockConfig, _Tp = ClockConfig, _Compare =
std::less<ClockConfig>, _Alloc = std::allocator<std::pair<const
ClockConfig, ClockConfig> >]'
Solver.cpp:55: instantiated from `void Solver<Config>::solve() [with
Config = ClockConfig]'
clock.cpp:60: instantiated from here
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/bits/stl_tree.h:993:
error: ISO C++ forbids incrementing a pointer of type `ClockConfig
(*)()'
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/bits/stl_tree.h:994:
error: no matching function for call to `std::_Rb_tree<ClockConfig,
std::pair<const ClockConfig, ClockConfig>,
std::_Select1st<std::pair<const ClockConfig, ClockConfig> >,
std::less<ClockConfig>, std::allocator<std::pair<const ClockConfig,
ClockConfig> > >::insert_unique(ClockConfig (&)())'
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/bits/stl_tree.h:862:
note: candidates are: std::pair<typename std::_Rb_tree<_Key, _Val,
_KeyOfValue, _Compare, _Alloc>::iterator, bool> std::_Rb_tree<_Key,
_Val, _KeyOfValue, _Compare, _Alloc>::insert_unique(const _Val&) [with
_Key = ClockConfig, _Val = std::pair<const ClockConfig, ClockConfig>,
_KeyOfValue = std::_Select1st<std::pair<const ClockConfig,
ClockConfig> >, _Compare = std::less<ClockConfig>, _Alloc =
std::allocator<std::pair<const ClockConfig, ClockConfig> >]
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/bits/stl_tree.h:888:
note: typename std::_Rb_tree<_Key, _Val, _KeyOfValue,
_Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue,
_Compare, _Alloc>::insert_unique(std::_Rb_tree_iterator<_Val >, const
_Val&) [with _Key = ClockConfig, _Val = std::pair<const ClockConfig,
ClockConfig>, _KeyOfValue = std::_Select1st<std::pair<const
ClockConfig, ClockConfig> >, _Compare = std::less<ClockConfig>, _Alloc
= std::allocator<std::pair<const ClockConfig, ClockConfig> >]
*** Error code 1
make: Fatal error: Command failed for target `clock.o'
any help will be really appreciated!!!!
thanks a lot!!!

Jul 22 '05 #7
Stoian wrote:
thanks a lot, i actually didn't notice when i writing these 3 lines
here, so i just put "new" and didn't realise (i didn't actually paste
the code). Ok i tried the make pair, and i still have errors, I'm not
that good with using templates, but i think that the problem is with
defining a comparator, probably the default one doesn't work with
templates, i don't know.
The default one uses operator<, so your key type needs an operator<.
Here is what i did, and the error again:

50 Config temp;
51 std::map<Config, Config> seen;
52 seen.insert(std::make_pair(temp, temp));
bash-2.05$ make
g++ -ggdb -c change.cpp
....
/usr/local/gnu/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/
bits/stl_function.h:227: error: no match for 'operator<' in '__x <
__y'
*** Error code 1


The compiler is telling you that your key type (i.e. Config) doesn't have an
operator<. So you either need to use your own custom comparison
function/object or you need to overload operator< that compares two
instances of your Config class.

Jul 22 '05 #8

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

Similar topics

2
by: Sam | last post by:
I would like to store html templates in a database. By using perl I would like to retrive the template ask the user to fill the template and store the whole file is template + the user data in a...
2
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
3
by: Sandros | last post by:
Background: I'm collecting usability statistics for a group of applications. Each count has the following attributes: date, application, major heading, minor heading, count. My intent is to pull...
4
by: Pat Turner | last post by:
Hi, I have some XML like this: <family> <person name="bob"> <father ref="../../person" /> </person> <person name="charlie"> <child ref="../../person" />
16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
6
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows...
0
by: Piper707 | last post by:
I need help with using a general template which would process all tags other than the ones for which specific templates have been written. My XML looks like this: <ITEMS>...
1
by: oldgent | last post by:
I am having a problem installing the starter kits. I have reinstalled VS 2005, think that might be the problem. I then installed both 'Personal Website" and the "Club Website" starter kits. I...
28
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the...
6
by: John Larson | last post by:
Hi All, I am some information from INSPEC database records in XML to build a relational database of my own. I am currently trying to extract information by doing an XSLT transform of the XML...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.