473,625 Members | 3,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ne w, 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<cons t ClockConfig, ClockConfig> >, _Compare
= std::less<Clock Config>, _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<Clock Config>, _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<cons t ClockConfig, ClockConfig> >,
std::less<Clock Config>, std::allocator< std::pair<const ClockConfig,
ClockConfig> > >::insert_uniqu e(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<typen ame std::_Rb_tree<_ Key, _Val,
_KeyOfValue, _Compare, _Alloc>::iterat or, 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<cons t ClockConfig,
ClockConfig> >, _Compare = std::less<Clock Config>, _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>::iterat or std::_Rb_tree<_ Key, _Val, _KeyOfValue,
_Compare, _Alloc>::insert _unique(std::_R b_tree_iterator <_Val>, const
_Val&) [with _Key = ClockConfig, _Val = std::pair<const ClockConfig,
ClockConfig>, _KeyOfValue = std::_Select1st <std::pair<cons t
ClockConfig, ClockConfig> >, _Compare = std::less<Clock Config>, _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 2056
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(ne w, 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_un ique(ClockConfi g (&)())

But a :
....::insert_un ique(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.goo gle.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);

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(tem p, 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()(con st _
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<type name
std::_Rb_tree<_ Key,
_Val, _KeyOfValue, _Compare, _Alloc>::iterat or, 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::p air<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<type name
std::_Rb_tree<_ Key,
std::pair<const _Key, _Tp>, std::_Select1st <std::pair<cons t _Key, _Tp>, _Compa

re, _Alloc>::iterat or, bool> std::map<_Key, _Tp, _Compare,
_Alloc>::insert (const
std::pair<const _Key, _Tp>&) [with _Key = ChangeConfig, _Tp =
ChangeConfig, _Co
mpare = std::less<Chang eConfig>, _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(tem p, 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.g oogle.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(ne w, 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<cons t ClockConfig, ClockConfig> >, _Compare
= std::less<Clock Config>, _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<Clock Config>, _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<cons t ClockConfig, ClockConfig> >,
std::less<Clock Config>, std::allocator< std::pair<const ClockConfig,
ClockConfig> > >::insert_uniqu e(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<typen ame std::_Rb_tree<_ Key, _Val,
_KeyOfValue, _Compare, _Alloc>::iterat or, 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<cons t ClockConfig,
ClockConfig> >, _Compare = std::less<Clock Config>, _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>::iterat or std::_Rb_tree<_ Key, _Val, _KeyOfValue,
_Compare, _Alloc>::insert _unique(std::_R b_tree_iterator <_Val>, const
_Val&) [with _Key = ClockConfig, _Val = std::pair<const ClockConfig,
ClockConfig>, _KeyOfValue = std::_Select1st <std::pair<cons t
ClockConfig, ClockConfig> >, _Compare = std::less<Clock Config>, _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(tem p, 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
5943
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 database. How can I do this? Should I use Perl Mason to do this. Or Can I store the template in database using text field and then retrive the template from database using select command and then save the html template to a file. Then in form...
2
3397
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 happening when I put my XML files and the .xsl files on my ISP's system for my home page. If I try to open the XML files in Netscape 7.0 on my own machine (ie, not on the ISP's system), the pages convert file and the result is displayed in HTML.
3
2469
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 this back as XML and render it in to an HTML table. I have all this working and all the files are below. I would value any feedback. A simple example of the data looks like this:
4
3445
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
16268
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
2156
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 XP Pro SP 1, .Net Framework 1.1) and on our production server (Windows 2K SP 4, .Net Framework 1.1). I have simplified the code and data to isolate the problem. When I use the xsl:strip-space (Line 12) declaration in conjunction with the xsl:sort...
0
1318
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> <SPECIAL1>abc</SPECIAL1> <SPECIAL2>abc</SPECIAL2> ... <SPECIAL12>abc</SPECIAL9>
1
1596
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 still have the same problem. Any web starter kit that is installed under 'My Templates" does not allow you to enter the location directory or use the browse button. Neither the "Personal Website" or the "Club Website" allows you to select the...
28
2623
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 executable size. This should not cause any performance issue. So, is it safe to say that if I can offered to have bigger image size I can go ahead and use Templates with out worrying about any other issues?
6
3724
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 files into a tab-separated text file that I want to import into the database. I have run into the following problem: in some documents there are missing elements, for instance the volume and issue number of an article is not there (i.e. it is defined...
0
8192
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8696
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6119
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5571
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4195
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1504
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.