•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,647 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,141 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 736 | Replies: 3 | Solved
![]() |
Hello everyone!
I have a function to get data from a database. I want to put it into matrix of some sort so that I can have something like a spreadsheet (multiple columns and rows, depending on data). It needs to be dynamic. Ok code so far -
Now when I try to compile it sais
What am I doing wrong? How can I return a 2-dimensional string matrix from a function? Thank you.
I have a function to get data from a database. I want to put it into matrix of some sort so that I can have something like a spreadsheet (multiple columns and rows, depending on data). It needs to be dynamic. Ok code so far -
//---------------------------------------------------------------
template <typename T>
class dynamic_array
{
public:
dynamic_array(){};
dynamic_array(int rows, int cols)
{
for(int i=0; i<rows; ++i)
data_.push_back(std::vector<T>(cols));
}
...
};
//---------------------------------------------------------------
//---------------------------------------------------------------
dynamic_array<string>* runMatrix(string sql)
{
dynamic_array<string>* res = new dynamic_array<string>(nrow, ncol);
....
return res;
}
//---------------------------------------------------------------
//---------------------------------------------------------------
int main()
{
dynamic_array<Glib::ustring>* res= runMatrix("select name from albums");
/* access the matrix here */
delete res;
}Now when I try to compile it sais
undefined reference to `runMatrix(string)'
What am I doing wrong? How can I return a 2-dimensional string matrix from a function? Thank you.
Last edited by linux0id : Apr 22nd, 2008 at 3:49 am.
sorry I forgot to remove the library:: bit. I have it correct in my code (ie ... = m_library.runMatrix("..")), but it still sais undefined reference!
Edit - If I create another function almost exactly like this, but have a 2d array of integers (i.e. int[5][5]), it works fine! If I replace the string with something else, like int, the result is the same.
Edit - If I create another function almost exactly like this, but have a 2d array of integers (i.e. int[5][5]), it works fine! If I replace the string with something else, like int, the result is the same.
Last edited by linux0id : Apr 22nd, 2008 at 3:57 am. Reason: forgot to mention...
I have managed to find a solution to this reading this guide - http://www.devx.com/tips/Tip/33488
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- missing (C++)
- (reformatted) How to return Multi-Dimensional Arrays (C++)
- Transpose & Inverse Matrix, Matrix Determinant (C++)
- i don't even know where to start (C++)
- Please helpwith how to return two dimensional array (C++)
- Return a 2D array from a function (C++)
- PHP 'explode()' in C++ ? (C++)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- Passing a filestream, how? (C++)
- Messy array things. (C++)
Other Threads in the C++ Forum
- Previous Thread: do while loop help
- Next Thread: Inserting node into lists


Linear Mode