0

Can`t I perform typedef inside the class?

#include <vector>
using namespace std;
    class List {
    public:
           typedef int Data;
           class iterator;
           pair<iterator,bool> insert(const Data nodeId); //<-error
    private:
    class Node {
        typedef vector<NodeId> DepList;//<-error
    };
    }

I get an error missing type specifier - int assumed. Note: C++ does not support default-int

YAKOVM
  • 9,805
  • 31
  • 116
  • 217
  • 2
    You should always be careful to see what line the error occurs on...I added `#include ` `using std::pair;` to the file and it compiled fine. – nneonneo Oct 08 '12 at 19:23
  • please provide complete code, information on the build and the (uncut) output of any warnings (`-Wall -Wextra -pedantic ...`). – moooeeeep Oct 08 '12 at 19:32

2 Answers2

1

You can.

I guess the error is on the line with the pair. Have you included the right header:

#include <utility>

Also, if you don't have using namespace std; or usgin std::pair;, you need to write std::pair, instead of just pair.

P.S. Please, don't use using namespace std;, especially header files.

EDIT Looking at your edit, you need #include <vector>, too.
EDIT2: You haven't defined NodeId, but you have used it for the typedef

Kiril Kirov
  • 37,467
  • 22
  • 115
  • 187
1

It's a misleading error message. Neither iterator, nor NodeId are defined, and so can't be used in expressions.

You could work with this (making iterator a reference to a forward declared class): pair<iterator&,bool> insert(const Data nodeId);

and add a forward declaration for NodeId: class NodeId;

then do: typedef vector<NodeId&> DepList;

Justicle
  • 14,761
  • 17
  • 70
  • 94