Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.g++.help > #338

Re: Trouble debugging some STL code

From Richard Kettlewell <invalid@invalid.invalid>
Newsgroups gnu.g++.help
Subject Re: Trouble debugging some STL code
Date 2018-01-25 19:52 +0000
Organization terraraq NNTP server
Message-ID <87d11xn2ca.fsf@LkoBDZeT.terraraq.uk> (permalink)
References <c23417d4-72c6-4190-9650-06e5e606b745@googlegroups.com>

Show all headers | View raw


"davin.pearson@gmail.com" <davin.pearson@gmail.com> 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/

Back to gnu.g++.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Trouble debugging some STL code "davin.pearson@gmail.com" <davin.pearson@gmail.com> - 2018-01-24 21:47 -0800
  Re: Trouble debugging some STL code Richard Kettlewell <invalid@invalid.invalid> - 2018-01-25 19:52 +0000
    Re: Trouble debugging some STL code "davin.pearson@gmail.com" <davin.pearson@gmail.com> - 2018-01-25 19:04 -0800
  Re: Trouble debugging some STL code "davin.pearson@gmail.com" <davin.pearson@gmail.com> - 2018-01-28 19:12 -0800
    Re: Trouble debugging some STL code Richard Kettlewell <invalid@invalid.invalid> - 2018-01-29 15:36 +0000
      Re: Trouble debugging some STL code "davin.pearson@gmail.com" <davin.pearson@gmail.com> - 2018-02-04 19:23 -0800
        Re: Trouble debugging some STL code Richard Kettlewell <invalid@invalid.invalid> - 2018-02-05 08:26 +0000

csiph-web