Thursday, July 9, 2009

How to initialise vector using own class in c++ STL?

Lets say i have my own class.. class Book{ };





how do i initialise it as a vector ? eg:


vector %26lt;Book%26gt; list;





That line doesnt work.. how do I make my class into a type name ??

How to initialise vector using own class in c++ STL?
Here you go:





#include "vector"





class Book


{


public:


Book(){}


// Other members here


};





typedef std::vector%26lt;Book%26gt; MYBOOKS;








int _tmain(int argc, _TCHAR* argv[])


{


MYBOOKS vBooks;





vBooks.push_back(Book());





return 0;


}





Hope this helps...

daisy

No comments:

Post a Comment