User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jul 2007
Posts: 37
Reputation: linux0id is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
linux0id's Avatar
linux0id linux0id is offline Offline
Light Poster

Return 2-dimensional vector array from function

  #1  
Apr 22nd, 2008
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 -
//---------------------------------------------------------------
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Posts: 858
Reputation: mitrmkar is a jewel in the rough mitrmkar is a jewel in the rough mitrmkar is a jewel in the rough 
Rep Power: 4
Solved Threads: 177
mitrmkar mitrmkar is offline Offline
Practically a Posting Shark

Re: Return 2-dimensional vector array from function

  #2  
Apr 22nd, 2008
runMatrix is a member function of library, so you need to either
1) instantiate an object of that class and call it like libraryObj.runMatrix(...)
or
2) if the runMatrix is a static function, then call it like library::runMatrix(...).
Reply With Quote  
Join Date: Jul 2007
Posts: 37
Reputation: linux0id is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
linux0id's Avatar
linux0id linux0id is offline Offline
Light Poster

Re: Return 2-dimensional vector array from function

  #3  
Apr 22nd, 2008
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.
Last edited by linux0id : Apr 22nd, 2008 at 3:57 am. Reason: forgot to mention...
Reply With Quote  
Join Date: Jul 2007
Posts: 37
Reputation: linux0id is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
linux0id's Avatar
linux0id linux0id is offline Offline
Light Poster

Re: Return 2-dimensional vector array from function

  #4  
Apr 22nd, 2008
I have managed to find a solution to this reading this guide - http://www.devx.com/tips/Tip/33488
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 3:02 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC