How to fix clang libc ++ error on Mac: private constructor call

I am trying to compile (private) C ++ software with Clang and libC ++ on Mac OS X 10.10 and get this error:

error: calling a private constructor of class 'std::__1::__wrap_iter<unsigned short *>'

      

Complete error message here .

Can someone please explain this error and how to fix it? A small self-contained example of the code that leads to this error, and being able to rewrite it to work would be great!

0


source to share


1 answer


Are you asking for a self-contained example showing the error but haven't provided your own example? This is not how stackoverflow works, you have to show the code so people don't know the problem!

This results in an error:

#include <vector>

void f(unsigned short* p)
{
    std::vector<unsigned short>::iterator i(p);
}

      

It looks like you are trying to build an iterator from a pointer, which is not valid (it may work with some compilers, but is not portable).



You can try using pointer arithmetic to get an iterator instead:

std::ptrdiff_t d = std::distance(vec.data(), p);
std::vector<unsigned short>::iterator i = vec.begin() + d;

      

This assumes it p

really points to an element of the vector, otherwise distance(vec.data(), p)

there is undefined.

+3


source







All Articles