-4

I'm getting the following compilation error:

expected unqualified-id before ‘[’ token Vector

const std::vector<double>* t_vector = &my->thresholds;

if(t_vector.size >= 10)
{
  std::cout << t_vector->[i];
}

The error is at the std::cout statement

I've also tried the following:

std::cout << t_vector[i]
std::cout << *t_vector[i]
tim_la_amzn
  • 35
  • 1
  • 7
  • @cbel Neither less worse: `threshold_vector->[i];` The OP should get a book about c++ basics, but certainly not ask here! – πάντα ῥεῖ May 13 '14 at 02:41
  • -1 because these are really trivial mistakes and you should learn from [a good book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) before resorting to asking here. – Lightness Races in Orbit May 13 '14 at 09:11

2 Answers2

1

This threshold_vector->[i] syntax simply does not exist.

You meant to dereference threshold_vector:

*threshold_vector

then invoke the [] operator on the result; to do so, you need to use a parenthesis:

(*threshold_vector)[i]

The -> syntax only works for function calls (be they of the form obj->foo() or obj->operator[](i)!), not the infix/prefix/postfix operators, due to various complexities of the language's grammar.

Similarly, write threshold_vector->size() not threshold_vector.size.

Also, hopefully, you meant std::vector<double> and not std::double<vector>?!

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • Nitpick: "The -> syntax only works for non-operator function calls" - `threshold_vector->operator[](i)` should work too :o) – Appleshell May 13 '14 at 02:16
0

beside mistakes that mentioned above you must note that since threshold_vector is declared as a pointer you may face problem compiling if(threshold_vector.size >= 10).

use threshold_vector->size instead. again im not sure that vector template has a field called size. it is a property i guess.

Sachamora
  • 479
  • 2
  • 13