1

I am using Netbeans 7.1 on Ubuntu 11.04.

The following call

set< Triangle > V;

gives the error message

error: ‘set’ was not declared in this scope

and the following call

vector< Triangle > ans;

gives the error message

error: ‘vector’ was not declared in this scope

This despite my having

#include <vector>
#include <set>
#include <map>

at the beginning of the C++ file.

At help resolving this would be greatly appreciated.
Peter.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
OtagoHarbour
  • 3,969
  • 6
  • 43
  • 81

3 Answers3

6

Vectors Sets and map are part of the c++ Standard Library so you need to call vector/set/map with

std::vector< Triangle > ans;

or add

using namespace std;

after the include statements.

Sam Coulter
  • 708
  • 1
  • 6
  • 27
  • 1
    `namespace std` isn't part of the STL. It is, however, part of the C++ Standard Library. – Ben Voigt Feb 11 '12 at 20:13
  • Oh Woopsy. Thanks, I just woke up and brain farted. Will edit. – Sam Coulter Feb 11 '12 at 20:15
  • I added using namespace std; after the include statements. That appears to have fixed it. Thank – OtagoHarbour Feb 11 '12 at 20:19
  • Please never, ever add `using namespace std;` to your code. Just spell out the namespace; you do have that much time. – Kerrek SB Feb 11 '12 at 21:29
  • 1
    @KerrekSB: Well, I wouldn't say *never, ever*. Never put it in a header, granted, but if I am writing a simple utility and pulling in the whole namespace makes things simpler without causing any problems I think it's fine. – Ed S. Feb 11 '12 at 22:36
3

you forgot about namespace std :

std::set< Triangle > V; std::vector< Triangle > V;

axelBrain
  • 46
  • 2
2

They live in the std namespace. So, either fully quality the types (std::vector) or use a using statement (using namespace std;).

The latter option pollutes the global namespace. Never do that in a header file (otherwise the entire namespace is imported when you include the header) and only do it in your implementation file if you know that it isn't going to cause any collisions.

#include <vector>

int main(...) {
    vector v;      // no worky
    std::vector v; // ok!
}
Ed S.
  • 122,712
  • 22
  • 185
  • 265