how to typedef a vector of a custom class?

14,562

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();
};
Share:
14,562
YNWA
Author by

YNWA

Updated on June 14, 2022

Comments

  • YNWA
    YNWA over 1 year

    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 ?