don't understand "insert" is ambiguous error message

Code below compiles and run with VS2013 but it does not compile with g++ 4.8.2. Getting 'insert' is ambiguous error message. Spent many hours trying to figure it out but no luck. My guess would be that insert does not like how it's being called.

thanks;

'insert' is ambiguous '
Candidates are:
void insert(__gnu_cxx::__normal_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char>> *,
std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,
std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>>>,

__gnu_cxx::__normal_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char>> *,
std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,
std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>>>,

__gnu_cxx::__normal_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char>> *,
std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,std::allocator<std::basic_string<char,
std::char_traits<char>,std::allocator<char>>>>>)

1
2
3
4
5
6
  	typedef std::vector<std::string> Filetype;
		Filetype myDoc, insertpoint,slice;
				
		Filetype::iterator itx = std::find(myDoc.begin(), myDoc.end(), *(--insertpoint.end()));
		++itx;
		myDoc.insert(itx, slice.begin(), slice.end());
I'm not really sure what it wants. This is the single candidate simplified:
1
2
3
void insert(__gnu_cxx::__normal_iterator<std::string *,std::vector<std::string>>,
__gnu_cxx::__normal_iterator<std::string *,std::vector<std::string>>,
__gnu_cxx::__normal_iterator<std::string *,std::vector<std::string>>) 
Which is what you have there.
Maybe make the types explicit?
 
myDoc.insert((Filetype::iterator)itx, (Filetype::iterator)slice.begin(), (Filetype::iterator)slice.end());
Have you included <algorithm>?

http://www.cplusplus.com/reference/algorithm/find/?kw=find


Edit: Tried without including algorithm and the error is with find not insert.

Anyway the following works here:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
#include <vector>
#include <algorithm>

int main()
{
    typedef std::vector<std::string> Filetype;
    Filetype myDoc, insertpoint,slice;
    myDoc.emplace_back("1");
    myDoc.emplace_back("2");
    myDoc.emplace_back("3");
    insertpoint.emplace_back("1");
    insertpoint.emplace_back("2");
    slice.emplace_back("slice");
    Filetype::iterator itx = std::find(myDoc.begin(), myDoc.end(), *(--insertpoint.end()));
    ++itx;
    myDoc.insert(itx, slice.begin(), slice.end());
    for(auto i : myDoc) {
        std::cout << i << std::endl;
    }
   return 0;
}
1
2
slice
3
Last edited on
The includes are in the file. I posted the part of the code that is failing to compile. It's a large
file (700 lines) and posting all of it is not feasible. Now, I'm totally confused.

Thank you;
What -std= do you give to the gcc?
-std=c++11
It is a very strange bacause it works as posted.
http://coliru.stacked-crooked.com/a/5867a9773d515720
Topic archived. No new replies allowed.