LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-19-2012, 07:38 PM   #1
fantasy1215
Member
 
Registered: Oct 2011
Posts: 75

Rep: Reputation: Disabled
How to let client using [i][j] access two dimension array?


I need to implement a class like a CMyResultSet class.
The client code which call CMyResultSet would look like this:
Code:
CMyResultSet res;
GetResultSet(res);
for (int i = 0; i < res.rows(); ++i)
{
    string res1 = res[i][0].tostring();
}
I have no idea how to implement [][] to let the client code calling like that. How would the method's prototype look like? And How can I save the searched result set in two dimension array, using std::vector or what?
Thanks in advance!
Sorry, I'm using C++!

Last edited by fantasy1215; 04-19-2012 at 09:02 PM.
 
Old 04-19-2012, 09:01 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
People frequently find it helpful in supporting you if you mention
the language you're using (no, not English, the programming language).
 
Old 04-24-2012, 11:41 AM   #3
TimothyEBaldwin
Member
 
Registered: Mar 2009
Posts: 249

Rep: Reputation: 27
Overload [] to return a object on which [] is overloaded appropriately.

Something like:
Code:
CMyResultSetProxy operator [] (int x) {
  return CMyResultSetProxy(*this, x);
}
CMyResultSetProxy would be something like:
Code:
class CMyResultSetProxy {
  CMyResultSet& ref;
  int x;
 public:
  CMyResultSetProxy(CMyResultSet& ref1, int x1) : ref(ref), x(x1) {}
  string operator [] (int y);
};
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Server array (mysql, php) -> gboolean array in c client kalleanka Programming 1 07-27-2010 06:50 AM
Multi dimension array... turn brain into mash potato! shylock_1 Programming 1 11-05-2009 08:38 PM
Many dimension array ratsietsi Programming 3 09-17-2006 01:28 PM
Multi-dimension array problem. ArthurHuang Programming 2 05-20-2006 09:36 AM
Reading from a txt file into a two dimension array in C kponenation Programming 3 11-26-2005 07:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration