🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Gary Lipton Thu, 09 Apr 1992 05:46
implicit member-wise assignment
#45
Author: Gary Lipton
Date: Thu, 09 Apr 1992 05:46
21 lines
884 bytes
I am just learning C++.  My references tell me that "=" is
implicitly defined as member-wise assignment between operands
of a given class.

That is, if I have a class "Foo", then the code

   Foo foo1, foo2;

   foo1 = foo2;

is legal, and will copy the members of foo1 into foo2, without
an explicit declaration of "=".

But I find that using g++, I would need the statement

  Foo operator=(Foo);

in my Class declaration for this code to compile.

Is there a way to get g++ to provide implicit assignment?  Or
am I on the wrong track entirely?
Re: implicit member-wise assignment
#69
Author: Don &
Date: Fri, 17 Apr 1992 06:44
50 lines
1664 bytes
>>>>> On 9 Apr 92 05:46:54 GMT, glipton@ajax.intel.com (Gary Lipton) said:

Gary> That is, if I have a class "Foo", then the code

Gary>    Foo foo1, foo2;

Gary>    foo1 = foo2;

Gary> is legal, and will copy the members of foo1 into foo2, without
Gary> an explicit declaration of "=".

Gary> But I find that using g++, I would need the statement

Gary>   Foo operator=(Foo);

Gary> in my Class declaration for this code to compile.

That's funny.  I'm using gcc-2.1 on a Sparc running SunOS4.1.1
and implicit assignment works fine for me.  The code appended
to this message comiles fine with the command "g++ assig.cc"

By the way, the usual assingment operator is

  Foo& operator=(const Foo&);

Don Bashford
bashford@scripps.edu

--------------------------assig.cc------------------------------
class Pub {
public:
  int x, y;
  Pub(int xc, int yc) {x = xc; y=yc;}
};

class Priv {
private:
  int x, y;
public:
  Priv(int xc, int yc) {x = xc; y=yc;}
};

main() {
  Pub pub1(2,3);
  Pub pub2(4,5);
  pub2 = pub1;
  Priv priv1(5,6);
  Priv priv2(7,8);
  priv2 = priv1;
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads