C ++中的指针原语类型? [英] Are pointers primitive types in C++?

查看:173
本文介绍了C ++中的指针原语类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 std :: string 的最后一个构造函数此处。它说:

I was wondering about the last constructor for std::string mentioned here. It says:

template<class InputIterator> string (InputIterator begin, InputIterator end);

如果 InputIterator 作为第六个构造函数版本(上面的一个)通过类型转换开始和结束调用它:

If InputIterator is an integral type, behaves as the sixth constructor version (the one right above this) by typecasting begin and end to call it:

string(static_cast<size_t>(begin),static_cast<char>(end));

在任何其他情况下,将参数作为迭代器,从迭代器引用的元素开始到迭代器结尾引用的元素之前的元素。

In any other case, the parameters are taken as iterators, and the content is initialized with the values of the elements that go from the element referred by iterator begin to the element right before the one referred by iterator end.

那么,如果 InputIterator char *

EDIT:好吧,我的坏。我只是意识到它说整数类型,而不是原始类型的文档,所以问题不适用于那个例子。但是仍然是指针原语?

Ok, my bad. I just realized that it says integral type, not primitive type in the documentation, so the question does not apply to that example. But still, are pointers primitives?

推荐答案

C ++没有原始类型的概念;整数是基本类型,指针是复合类型。

C++ doesn't have a concept of "primitive" types; integers are fundamental types and pointers are compound types.

在这种情况下, char * size_t char ,因此它将被视为 InputIterator 模板参数。

In this case, char* can't be converted into either size_t or char, so it will be taken as the InputIterator template parameter.

这篇关于C ++中的指针原语类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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