YAKOVM
YAKOVM

Reputation: 10153

typedef inside class

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

Upvotes: 0

Views: 7356

Answers (2)

Kiril Kirov
Kiril Kirov

Reputation: 38163

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

Upvotes: 1

Justicle
Justicle

Reputation: 15143

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;

Upvotes: 1

Related Questions