如何在Mac上修复clang libc ++错误:调用私有构造函数 [英] How to fix clang libc++ error on Mac: calling private constructor

查看:367
本文介绍了如何在Mac上修复clang libc ++错误:调用私有构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Mac OS X 10.10上使用Clang和libc ++编译一个(专用)C ++软件,并且出现此错误:

I'm trying to compile a (private) C++ software with Clang and libc++ on Mac OS X 10.10 and am getting this error:

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

完整错误消息此处.

有人可以解释此错误以及如何解决该错误吗? 一个很小的自包含代码示例会导致此错误,并提供了一种将其重新编写以使其正常工作的选项!

Can someone explain this error and how to fix it? A small self-contained code example that results in this error and an option how to re-write it so that it works would be great!

推荐答案

您要的是一个显示错误的独立示例,但没有提供您自己的示例吗?那不是stackoverflow的工作原理,而是要向您展示代码,不要让人们猜测这个问题!

You're asking for a self-contained example showing the error but haven't provided your own example? That's not how stackoverflow works, you are meant to show the code not make people guess at the problem!

这会产生错误:

#include <vector>

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

好像您正在尝试从指针构造迭代器一样,这是无效的(它可能适用于某些编译器,但不可移植).

Looks as though you're trying to construct an iterator from a pointer, which is not valid (it might work with some compilers, but is not portable).

您可以尝试使用指针算法来获取迭代器:

You could try using pointer arithmetic to get the iterator instead:

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

这假设p确实指向向量的元素,否则distance(vec.data(), p)未定义.

This assumes p really does point to an element of the vector, otherwise distance(vec.data(), p) is undefined.

这篇关于如何在Mac上修复clang libc ++错误:调用私有构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆