YNWA
YNWA

Reputation: 700

how to typedef a vector of a custom class?

I have class T defined and implemented with a default constructor, a copy constructor and an assignment operator overloaded

I have tried to do the following

      #include <vector>
      //template <class Board>
      typedef std::vector<Board> t_bvector;

with and without the comment, I am getting this error

../Piece.H:143:1: error: ‘t_bvector’ does not name a type
In file included from ../Board.C:1:0:
../Board.H:14:1: error: template declaration of ‘typedef’
In file included from ../Board.C:1:0:

I dont have C++11, and want to retain basic vector methods like .insert, .size is there a way to solve it? or a better suggestion for an STL container ?

Upvotes: 2

Views: 20360

Answers (2)

Don't forget declare the custom typedef statement after using namespace std; to prevent a similar error

Upvotes: 0

TheUndeadFish
TheUndeadFish

Reputation: 8171

I'm not sure what you're trying to do with that template <class Board> part but I'm guessing you've got some syntax wrong in your actual code or something misplaced.

Here is an example of how you should be trying to setup such a typedef.

#include <vector>

class Board
{
public:
    int foo;
};

typedef std::vector<Board> t_bvector;

EDIT

Now that you've explained a bit more:

class Board;
typedef std::vector<Board> t_bvector;

class Board
{
public:
    t_bvector SomeFunction();
};

Upvotes: 3

Related Questions