1

Some C++ methods I'm importing into an Android project convert a string to a vector like below (as here):

#include <string>
#include <vector>

void myMethod(std::string str) {
    std::vector<uint8_t> vec(str.begin(), str.end()); // error
}

While I do not get any build errors, Android Studio gives me a red line below vec(str.begin(), str.end()) stating

No matching constructor

The only constructor it suggests that has the __first and __last iterators has the following parameters:

_InputIterator __first, _InputIterator __last, const std::vector<unsigned char, std::__ndk1::allocator<unsigned char>>::allocator_type &__a, void * = 0

I would like to get rid of the red error line (tried these, didn't help), but I also do not want to spend extra time adapting C++ code that I supposedly should be able to more or less drop into the project. Do I need to worry about this as there are no build errors? If yes, how do I fix it?

I have installed every update offered by Android Studio to CMake, LLDB, NDK, etc.

Roope
  • 4,469
  • 2
  • 27
  • 51
  • 5
    If your IDE is telling you that there is a syntax error but the compiler successfully compiles your code then it's likely that your IDE is mistaken. While it's annoying, there doesn't seem to be anything wrong with your code. – François Andrieux Jan 04 '19 at 18:27
  • 1
    *Android Studio gives me a red line* -- Report the bug to Android Studio, or live with the fact that IDE's are not going to be as rigorous as a real C++ compiler. Also, do not needlessly change code just to make a non-build tool happy. If the compiler itself reports an error, fix the code. If the linker reports that it can't find certain functions, fix your project. But seriously, do not waste time trying to get a red squiggly or some highlighting to work properly by changing valid code. – PaulMcKenzie Jan 04 '19 at 18:36
  • @PaulMcKenzie Alright, that's what I thought. – Roope Jan 04 '19 at 18:47

0 Answers0