2

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 ?

Lightness Races in Orbit
  • 358,771
  • 68
  • 593
  • 989
YNWA
  • 618
  • 2
  • 8
  • 19
  • is it able to use common vector methods? like .insert, .size ? – YNWA Jun 21 '14 at 14:44
  • It's not at all clear what you're trying to do and what the problem is. I'm not even convinced that the duplicate is relevant. – Lightness Races in Orbit Jun 21 '14 at 15:00
  • maybe you need forward declaring Board class ?! – uchar Jun 21 '14 at 15:03
  • Hi, forward decaring isnt needed because I am writing this in the same file as the class what i want to do is simple - just declare a vector of my custom class – YNWA Jun 21 '14 at 15:24
  • Doesn't matter if it's in the same file if the denifition comes after the typedef. It's not clear in you question if that's the case. And no you don't add template before the typedef – JarkkoL Jun 21 '14 at 15:33
  • @YNWA, Is `Board` a class or a class template. From the commented out line in your posted code, it appears like it is a class template. – R Sahu Jun 21 '14 at 15:38

1 Answers1

2

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();
};
TheUndeadFish
  • 7,700
  • 1
  • 20
  • 16
  • hi, tis removes one error and adds a another. I want to use the new vector as a return for a Board method. ive tried using a forward decleration but didnt solve it, tried placing it after the class decleration also...any tips? – YNWA Jun 21 '14 at 15:37
  • @YNWA Then update your question with more of the actual code you've tried and the resulting error. I can't really guess what you've got, but I know my example works on its own. – TheUndeadFish Jun 21 '14 at 15:41
  • Forward declare Board, i.e. add class Board; before the typedef. And move those before the Board class definition – JarkkoL Jun 21 '14 at 15:42
  • hi, this solved some of the problems. but now I am having problems with uses of this new type in other files (that includes the .H with the class) error from other file - "error: ‘t_bvector’ does not name a type". posting the code - i can but its pretty long...very long – YNWA Jun 21 '14 at 15:56