Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using vs. typedef for std::vector::iterator

I am having a problem when using the new C++11 using keyword. As far as I understand, it's an alias for typedef. But I cannot get it to compile. I want to define an alias for an iterator of a std::vector. If I use this everything works perfectly.

typedef std::vector<fix_point>::iterator inputIterator;

But if I try:

using std::vector<fix_point>::iterator = inputIterator;

The code doesn't compile with:

Error: 'std::vector<fix_point>' is not a namespace
using std::vector<fix_point>::iterator = inputIterator;
                            ^

Why doesn't this compile?

like image 549
Foaly Avatar asked Nov 28 '22 14:11

Foaly


1 Answers

You just have it backwards:

using inputIterator = std::vector<fix_point>::iterator;

The alias syntax sort of mirrors the variable declaration syntax: the name you're introducing goes on the left side of the =.

like image 164
Barry Avatar answered Dec 01 '22 04:12

Barry