View Single Post
Old 08-20-2002, 08:38 AM   #4 (permalink)
sdeming
Code Monkey
 
Join Date: Jul 2002
Location: Michigan
Posts: 85
sdeming is on a distinguished road
If you are going to return a local variable then you must declare it static or it can be destroyed before you ever actually use it, like this:
Code:
char *Car::itsModel()
{
  static char[] model = "2002 Camarro SS +35";
  return model;
}
Even better would to be to throw out char* altogether and start using std::string, it's immensly more powerful and much much safer.
__________________
Scott
B4 09 BA 09 01 CD 21 CD 20 53 63 6F 74 74 24
sdeming is offline   Reply With Quote