www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/01/04/07:16:20

Subject: Default constructor & assignment operators
From: davidn AT csource DOT oz DOT au (david nugent)
Reply-To: davidn AT csource DOT oz DOT au
Date: Mon, 04 Jan 93 11:51:56 +1100
Organization: Unique Computing Pty Ltd, Melbourne, Australia
Apparently-To: <djgpp AT sun DOT soe DOT clarkson DOT edu>

I've hit a problem with using the default constructors & assigment
operators generated by gcc. This is probably a gcc problem, but I
thought I'd check with experience here before going further.

I have three simple objects:

  class Point
  {
    int x;
    int y;
  //...
  };
  class Vector
  {
    int dx;
    int dy;
  //...
  };
  class Area : public Point, public Vector
  {
  //...
  };

Each of these does define constructors, both with and without arguments.
The copy constructor and default constructors don't exist.

The problem seems to occur in the following code fragment:

  myfunc (const Area& a, const Point& o)
  {
  Area& x = a;

  //...

The initialisation, which should involve calling the copy constructor,
doesn't occur.  Only the default constructor is called.

Changing this to:

  myfunc (const Area& a, const Point& o)
  {
  Area& x;

  x = a;
  //...

.. and it works, so the compiler generated assignment operator works.

Has anyone had similar experiences?  If it is a gcc 2.2.2 bug, has it been
reported and fixed in 2.3.x?



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019