tags:

views:

158

answers:

2

for example we have following code pragment

#include <iostream>
#include <ostream>
#include <vector>
using namespace std;

int main() {
    vector<vector<int>>v;
    return 0;  
}

i have question as i see this form v.push_back(11) does not work what will be correct?

+2  A: 
vector<vector<int>>v;

needs to be

vector<vector<int> >v;

The consecutive >> acts as the actual >> operator.

advait
there should also be a space before `v`.
Amir Rachum
In Visual C++ 2008 Sp1 `vector<vector<int>> v;` is fine.
graham.reeds
OP is using C++0x.
KennyTM
Actually, this is correct (has been fixed) in `C++0x`.
ereOn
...and most modern compilers.
Blindy
@Blindy: If modern compilers are not interpreting >> as the operator >> then they are incorrect (So I doubt that statement is correct). It is only valid to interpret them as closing template braces when compiling C++0x where the language definition has been changed to allow for this. If different compilers interpreted the same source in different ways we would be back in the 60's (standards conformance is everything nowadays).
Martin York
@Martin York, parsing >> as the closing part of a template is actually unambigous. There is no possible way of using the >> operator WITHIN a template type and make it a legal statement. Also pick up a copy of VS 2010 and try it for yourself.
Blindy
And it's not about interpreting it "differently", it's either interpreting it the right way (C++0x) or erroring out (your 60's compilers, mind you we live in 2010).
Blindy
@Blindy: Big claim for `unambigous` :-). I bet this `T1<T2< a >> b > > d;` is parsed differently in C++03 and C+0x. I would expect this to be a variable declaration for 'd' but if you parse '>>' as two seprate tokens (as you could in C++0x) then it is a syntax error.
Martin York
I see what you're saying and that can be (and is) fixed by adding parantheses to your expression: `T1<T2< (a >> b) > > d;`. This works in both current C++ and C++0x.
Blindy
+6  A: 
#include <iostream>
#include <ostream>
#include <vector>
using namespace std;

int main() {
    vector<vector<int> >v;
    vector<int> a;
    a.push_back(11);
    v.push_back(a);
    return 0;  
}

I think this should work right :)

Arjit
"this should work" is a clear sign of a potentially broken code ;) the obvious syntax error: `>>` -> `> >`
Dummy00001
Yea right !! i was wrong :P
Arjit