C++ question

Christian Flöter cfloeter at gmx.de
Sun Feb 10 15:21:08 PST 2002


Hi GCC users,

I've tried this little C++ source which I found on the net. It compiles
and links OK (Unixlib), but when run, it aborts. I'm using GCC 2.95.4 on
a SARPC/RO3.7.

Apart from this example, GCC works fine for me.  What's wrong here?


Greetings,

-- 
Christian. <cfloeter at gmx.de>  http://lightning.prohosting.com/~cfloeter
-------------- next part --------------
#include <iostream.h>
#include <string.h>

class person
{
public:

   char *name;
   int age;

   person (char *n = "no name", int a = 0)
   {
      name = new char[100];
      strcpy (name, n);
      age = a;
   }

   person (person &s)               // The COPY CONSTRUCTOR
   {
      strcpy (name, s.name);
      age = s.age;
   }

   ~person ()
   {
      delete [] name;
   }
};

void main ()
{
   person p;
   cout << p.name << ", age " << p.age << endl << endl;

   person k ("John", 56);
   cout << k.name << ", age " << k.age << endl << endl;

   p = k;
   cout << p.name << ", age " << p.age << endl << endl;

   p = person ("Bob", 10);
   cout << p.name << ", age " << p.age << endl << endl;
}


More information about the gcc mailing list