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 403,237 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 4,039 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

Simple solution to database

Join Date: Jun 2007
Location: Shanghai
Posts: 16
Reputation: kinggarden is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
kinggarden kinggarden is offline Offline
Newbie Poster

Re: Simple solution to database

  #9  
Jun 13th, 2007
Originally Posted by Narue View Post
>What to return?
An exception is the better option in this case. But if you want to return something, you need to pick a string that couldn't possibly be in the database. That's difficult to do, so you might do well to add a level of indirection by using an object for each cell rather than a string. Then you can easily give it a null value and any other cellish information that isn't easily derived from the value:
class Cell {
  bool is_null;
  std::string value;
public:
  Cell ( const std::string& init = "" )
    : is_null ( init.size() == 0 ), value ( init )
  {}
public:
  const std::string& GetValue() const
  {
    return value;
  }
 
  void SetValue ( const std::string& s )
  {
    value = s;
    is_null = false;
  }
 
  bool IsNull() const
  {
    return is_null;
  }
};


Thank u very much.

But I still have a question, if I write something like this

  1.  
  2. const Cell & Test() {
  3.  
  4. return NULL; //I just want to tell something is wrong
  5. }
  6.  
  7.  

Of course, I defined a copy constructor in Class Cell like this

  1. Cell(const int i) {
  2. if(0 == i) is_null =true;
  3. }

But it doesn't work well, there is a waring "returning address of local

variable or temporary". I know that, a temp object is generated in

Test and the reference of that object is returned.

In fact, i think Test() returns a reference of something, it must be

a long life object(i mean not temp or local). But at that time, i don't

have such a object, how to return?

Thank you
Rock Mu

I will keep walking!

Shanghai, China
Reply With Quote  
All times are GMT -4. The time now is 5:39 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC