Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Say I have an object of some of stl container classes obj. I can define other object of same type this way:

decltype(obj) obj2;

But I can't declare iterator for the container this way:

decltype(obj)::iterator it = obj.begin();

Why? Am I doing something wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
144 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your code is well-formed according to the final C++0x draft (FDIS). This was a late change that's not yet been implemented by the Visual Studio compiler.

In the meantime, a workaround is to use a typedef:

typedef decltype(obj) obj_type;
obj_type::iterator it = obj.begin();

EDIT: The relevant chapter and verse is 5.1.1/8:

qualified-id:
    [...]
    nested-name-specifier template
opt unqualified-id nested-name-specifier: [...] decltype-specifier :: decltype-specifier: decltype ( expression )

And for completeness's sake:

The original core issue

Proposal for wording


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...