Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

:: scope resolution operator

78 views
Skip to first unread message

Doug Mika

unread,
Jul 17, 2015, 12:52:39 PM7/17/15
to
Hi to all

I have been reading about C++ for a while, but I must admit, that one of the things that I find confusing is all the instances when you use the scope resolution operator ::. Namespaces, inheritence, etc...

So it begs the question, when we write vector<int>::const_iterator myIterator
can I deduce from this that const_iterator is an inner class of vector<int> class? Is it?

Does anyone know of a easy to read and comprehensive introduction to how/when/why to use the scope resolution operator?

red floyd

unread,
Jul 17, 2015, 1:08:54 PM7/17/15
to
On 7/17/2015 9:52 AM, Doug Mika wrote:
> Hi to all
>
> I have been reading about C++ for a while, but I must admit, that one of the things that I find confusing is all the instances when you use the scope resolution operator ::. Namespaces, inheritence, etc...
>
> So it begs the question, when we write vector<int>::const_iterator myIterator
> can I deduce from this that const_iterator is an inner class of vector<int> class? Is it?
>

No. It is a *typename* that is defined within vector<int>. It is not
necessarily an inner class.

Example:

class A {
public:
typedef int integral_type;
};

A::integral_type x = 0;

x is of type int.



Doug Mika

unread,
Jul 17, 2015, 2:10:20 PM7/17/15
to
So what precisely is the line inside vector<T>

typedef ? const_iterator;

Jorgen Grahn

unread,
Jul 17, 2015, 2:51:16 PM7/17/15
to
*Shrug* Call me lazy, but I use :: when I have to; when the compiler
refuses to understand me if I don't.

For vector<int>::const_iterator it's obvious that I have to; there is
no all-purpose "const_iterator", and I'm not inside the implementation
of vector<int>, so I have to be specific (or use "auto").

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Paavo Helde

unread,
Jul 17, 2015, 3:16:20 PM7/17/15
to
Doug Mika <doug...@gmail.com> wrote in
news:2f529752-4a8f-448f...@googlegroups.com:

> So what precisely is the line inside vector<T>
>
> typedef ? const_iterator;

http://www.learncpp.com/cpp-tutorial/46-typedefs/

Öö Tiib

unread,
Jul 17, 2015, 3:27:53 PM7/17/15
to
It is required to be a type that fulfills requirements to random access
iterator to const T.
http://www.cplusplus.com/reference/iterator/RandomAccessIterator/

What it really is may depend on compiler options. Compiler's
documentation may specify more about it but usage of such
implementation-specific knowledge results with non-portable code.

Louis Krupp

unread,
Jul 19, 2015, 6:49:54 AM7/19/15
to
On Fri, 17 Jul 2015 09:52:11 -0700 (PDT), Doug Mika
<doug...@gmail.com> wrote:

.. snip ..
>So it begs the question, when we write vector<int>::const_iterator myIterator
>can I deduce from this that const_iterator is an inner class of vector<int> class? Is it?

To be pedantic, it doesn't *beg* the question, it *raises* the
question. Hopefully, this link is accessible without a New York Times
subscription:

http://afterdeadline.blogs.nytimes.com/2008/09/25/begging-the-question-again/

That links to this page, which might be helpful:

http://begthequestion.info/

And what's C++ all about, if it's not about being pedantic? :)

Louis
Message has been deleted

Richard

unread,
Jul 20, 2015, 2:59:39 PM7/20/15
to
[Please do not mail me a copy of your followup]

Louis Krupp <lkr...@nospam.pssw.com.invalid> spake the secret code
<6tvmqald55cj4d19q...@4ax.com> thusly:

>And what's C++ all about, if it's not about being pedantic? :)

s/C++/comp.lang.c++/ and I'm in agreement.

A tautology is a thing that is tautological.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>

red floyd

unread,
Jul 21, 2015, 11:20:05 AM7/21/15
to
On 7/20/2015 11:59 AM, Richard wrote:
>
> A tautology is a thing that is tautological.
>

https://xkcd.com/703/


0 new messages