这个指针操作有其他语法吗? [英] Is there other syntax for this pointer operation?

查看:104
本文介绍了这个指针操作有其他语法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个真正的基本问题,但我不知道如何google它。

This is a really basic question, but I'm not sure how to google it.

我有一个指针指向一个向量(或指针数组)说

I have a pointer to a vector (or array of pointers), say

vector<int *> *p;

除了

(*p)[i];

类似于 - >运算符?

akin to the -> operator?

推荐答案

p->在(i)是类似的,但如果 i 超出范围。看起来比你和Luchian的解决方案(IMO)更好,更安全一些。

p->at(i) is similar but does bounds checking and throws an exception if i is out of range. Looks nicer than both your and Luchian's solutions (IMO), and is a little safer.

这篇关于这个指针操作有其他语法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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