[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Trouble debugging some STL code
From: |
address@hidden |
Subject: |
Re: Trouble debugging some STL code |
Date: |
Thu, 25 Jan 2018 19:04:07 -0800 (PST) |
User-agent: |
G2/1.0 |
Thank you for taking the time to fix my bug. It becomes obvious when the
solution is presented to me.
On Friday, January 26, 2018 at 8:52:06 AM UTC+13, Richard Kettlewell wrote:
> writes:
> > std::ostream& operator << (std::ostream& o, const
> > std::map<std::string,int>& map)
> > {
> > typename std::map<std::string,int>::iterator it = map.begin();
>
> [...]
>
> > cd ~/lisp++-projects && make 2018/map/map5.run
> > make: Warning: File '2006/libd/libd.o' has modification time 26862 s in the
> > future
> > * Compiling 2018/map/map5.cc DEBUG
> > g++ -g -O0 -std=c++11 -W -Wall -Wpointer-arith -Wformat -ffast-math
> > -fno-permissive -Wno-format-contains-nul -c 2018/map/map5.cc -o
> > 2018/map/map5.o
> > 2018/map/map5.cc: In function ‘std::ostream& operator<<(std::ostream&,
> > const std::map<std::__cxx11::basic_string<char>, int>&)’:
> > 2018/map/map5.cc:16:63: error: conversion from
> > ‘std::map<std::__cxx11::basic_string<char>, int>::const_iterator {aka
> > std::_Rb_tree_const_iterator<std::pair<const
> > std::__cxx11::basic_string<char>, int> >}’ to non-scalar type
> > ‘std::map<std::__cxx11::basic_string<char>, int>::iterator {aka
> > std::_Rb_tree_iterator<std::pair<const std::__cxx11::basic_string<char>,
> > int> >}’ requested
> > typename std::map<std::string,int>::iterator it = map.begin();
> > ^
> > Makefile.mk:66: recipe for target '2018/map/map5.o' failed
> > make: *** [2018/map/map5.o] Error 1
> >
> > Compilation exited abnormally with code 2 at Thu Jan 25 18:45:24
> > Compilation started at: 20180125-184522
> > compilation-start-time=(23145 28402 353882 710000)
> > compilation-stop-time=(23145 28404 423781 491000)
> > Compilation took 2 seconds
> >
> > What gives with the error message? What mm I doing wrong?
>
> You’ve got a const_iterator, you’re trying to convert it to an
> iterator.
>
> At a higher level, arguably what you’re doing wrong is typing out
> complete (incorrect) type names instead of using ‘auto’.
>
> --
> https://www.greenend.org.uk/rjk/