By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,953 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,953 IT Pros & Developers. It's quick & easy.

Allocating std::vector<std::vector<T> > on the heap

P: 4
Hi all,
I'm new of c++ and i'm writing a class that create a matrix of data (of T type, it's a template class).
The member variable m_data must stores the matrix's data and i prefer use heap
so, i need to allocate the std::vector<std::vector<T> > member variable with new operator.
How can i?
Jul 29 '07 #1
Share this Question
Share on Google+
1 Reply

P: 4
The class is very simple:

template <typename T>
class TableLib
TableLib(int rows, int cols):m_data(rows, std::vector<T>(cols)){}
std::vector<T> & operator[](int);
const std::vector<T> & operator[] (int) const;
void Resize(int , int );


std::vector<std::vector<T> > m_data;

(Resize member function is implemented in another file, but it's implementation is not important now).

Actually m_data is created on the stack (right??). I must allocate it on the heap.
Anyone help me?
Jul 29 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.