Topic: default assignment


Author: jam <farid.mehrabi@gmail.com>
Date: Mon, 25 Jun 2007 11:52:58 CST
Raw View
===================================== MODERATOR'S COMMENT:
 Please try to keep any follow ups on-topic for comp.std.c++.

------=_Part_5415_24767235.1182790365176
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

approve<br>comment Please try to keep any follow ups on-topic for comp.std.c++.<br><br>

------=_Part_5415_24767235.1182790365176--


===================================== END OF MODERATOR'S COMMENT
On Jun 24, 10:40 pm, Daniel Kr   gler <daniel.krueg...@googlemail.com>
wrote:
> On 24 Jun., 17:21, jam <farid.mehr...@gmail.com> wrote:
>
> > #include<conio.h>
>
> This is some non-standard header.

It used to be part of C
>
> > #include<iostream.h>
>
> Should probably be #include<iostream>, because
> <iostream.h> was never part of the official standard.
>

Yes,actually MS.net  had similar complaign as yours.But borland
builder is a bit old and the extention was essential ,this one
complained about namespace std.
But fixing this and  leaving  the other parts untouched the resulting
output  was the same.

> > struct A{
> >         A(){cout<<"start A"<<endl;};
> >         A& operator=(const A&){cout<<"assign A"<<endl;return *this;};
> >         ~A(){cout<<"finish A"<<endl;};
> > };
>
> You did not handle the copy c'tor. Was this an oversight or
> by design?
>
Yes,leting ctor/dtor`s twice execution would not help me.
> > int main()
> > {
> >         E e1;
> >         endl(cout);
> >         {
> >                 E e2=e1;
>
> This one invokes the copy c'tor and thus should not
> output anything.
ctor for 'e1' does what we need.

I wonder how you forgot to object the use of none-streaming IO funxn
'getch()' (it is supposed to censor the output for 'e1._dtor()'  and
let the other outputs be observed) togather with 'cout'.I could not
figure out a satisfactory std solution to write it .

> Yes, the order of member and base class invokations of the implicitely
> generated copy-assignment operator is ruled by the standard. The
> corresponding section is [class.copy], p. 13:
>
> "The implicitly-defined copy assignment operator for class X performs
> memberwise assignment of its subobjects. The direct base classes of
> X are assigned first, in the order of their declaration in the base-
> specifierlist,
> and then the immediate nonstatic data members of X are assigned, in
> the
> order in which they were declared in the class definition.[..]"
>
> Please note that only virtual base classes have some unspecified
> parts of this assignment (I left this part out).
>
> And yes, above rules match the rules for initialization of bases and
> members inside any c'tor as described in [class.base.init].
>
thanks  a lot.
regards,
FM.


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: ricecake@gehennom.invalid (Marcus Kwok)
Date: Mon, 25 Jun 2007 17:15:40 GMT
Raw View
jam <farid.mehrabi@gmail.com> wrote:
> On Jun 24, 10:40 pm, Daniel Kr?gler <daniel.krueg...@googlemail.com>
> wrote:
>> On 24 Jun., 17:21, jam <farid.mehr...@gmail.com> wrote:
>>
>> > #include<conio.h>
>>
>> This is some non-standard header.
>
> It used to be part of C

I don't think so.  It may have been a standard header for MS compilers,
but AFAIK it was never standard C nor C++.

> I wonder how you forgot to object the use of none-streaming IO funxn
> 'getch()' (it is supposed to censor the output for 'e1._dtor()'  and
> let the other outputs be observed) togather with 'cout'.I could not
> figure out a satisfactory std solution to write it .

I guess you are just trying to make the window stay open when you
double-click on the program?  Try using cin.get() instead of the
non-standard getch().

--
Marcus Kwok
Replace 'invalid' with 'net' to reply

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: =?iso-8859-1?q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Mon, 25 Jun 2007 13:15:51 CST
Raw View
On 25 Jun., 19:52, jam <farid.mehr...@gmail.com> wrote:
> > > #include<conio.h>
>
> > This is some non-standard header.
>
> It used to be part of C

It is neither standard C nor standard C++. It's typically
part of (non-portable) MS-DOS-specific headers.

> > You did not handle the copy c'tor. Was this an oversight or
> > by design?
>
> Yes,leting ctor/dtor`s twice execution would not help me.

I don't understand what you mean with this. But I conclude
that the omission of the copy-c'tor is by design.

> I wonder how you forgot to object the use of none-streaming IO funxn
> 'getch()' (it is supposed to censor the output for 'e1._dtor()'  and
> let the other outputs be observed) togather with 'cout'.I could not
> figure out a satisfactory std solution to write it .

Actually I considered to do so, but were too lazy ;-)

I assume you can use either getchar() from stdio.h/cstdio
or, as Marcus wrote, you could try std::cin.get().

Greetings from Bremen,

Daniel Kr   gler



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: jam <farid.mehrabi@gmail.com>
Date: Tue, 26 Jun 2007 12:50:43 CST
Raw View
===================================== MODERATOR'S COMMENT:
 Please keep follow ups on-topic, i.e., related to standardization of
C++.

------=_Part_23731_11983905.1182880229908
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

approve<br>comment Please keep follow ups on-topic, i.e., related to standardization of C++.<br><br>

------=_Part_23731_11983905.1182880229908--


===================================== END OF MODERATOR'S COMMENT
On Jun 25, 11:15 pm, Daniel Kr   gler <daniel.krueg...@googlemail.com>
wrote:
> On 25 Jun., 19:52, jam <farid.mehr...@gmail.com> wrote:
>
> > > > #include<conio.h>
>
> > > This is some non-standard header.
>
> > It used to be part of C
>
> It is neither standard C nor standard C++. It's typically
> part of (non-portable) MS-DOS-specific headers.
>
That`s it.
> > > You did not handle the copy c'tor. Was this an oversight or
> > > by design?
>
> > Yes,leting ctor/dtor`s twice execution would not help me.
>
> I don't understand what you mean with this. But I conclude
> that the omission of the copy-c'tor is by design.
>

I just needed a comparison between ctor/dtor and assignment.And I
needed neither to polute the output.

> > I wonder how you forgot to object the use of none-streaming IO funxn
> > 'getch()' (it is supposed to censor the output for 'e1._dtor()'  and
> > let the other outputs be observed) togather with 'cout'.I could not
> > figure out a satisfactory std solution to write it .
>
> Actually I considered to do so, but were too lazy ;-)
>
> I assume you can use either getchar() from stdio.h/cstdio
> or, as Marcus wrote, you could try std::cin.get().

neither is as clean as 'getch' it does not print the read character
and on some platforms does not wait for 'enter', just a key press and
there you are.Is there a counterpart in streaming IO?(some thing that
at least does not echo the character)

regards,
FM.


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: ricecake@gehennom.invalid (Marcus Kwok)
Date: Tue, 26 Jun 2007 19:53:52 GMT
Raw View
jam <farid.mehrabi@gmail.com> wrote:
> On Jun 25, 11:15 pm, Daniel Kr?gler <daniel.krueg...@googlemail.com>
> wrote:
>> I assume you can use either getchar() from stdio.h/cstdio
>> or, as Marcus wrote, you could try std::cin.get().
>
> neither is as clean as 'getch' it does not print the read character
> and on some platforms does not wait for 'enter', just a key press and
> there you are.Is there a counterpart in streaming IO?(some thing that
> at least does not echo the character)

No, see FAQ #15.17 and #15.18:
http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.17

I do not think that it is possible to standardize this feature, since
(as the FAQ states) C++ doesn't even require the system to have a
keyboard nor a screen.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: jam <farid.mehrabi@gmail.com>
Date: Sun, 24 Jun 2007 09:21:16 CST
Raw View
consider this code:

#include<conio.h>
#include<iostream.h>
using namespace std;

struct A{
 A(){cout<<"start A"<<endl;};
 A& operator=(const A&){cout<<"assign A"<<endl;return *this;};
 ~A(){cout<<"finish A"<<endl;};
};

struct B{
 B(){cout<<"start B"<<endl;};
 B& operator=(const B&){cout<<"assign B"<<endl;return *this;};
 ~B(){cout<<"finish B"<<endl;};
};

struct C{
 C(){cout<<"start C"<<endl;};
 C& operator=(const C&){cout<<"assign C"<<endl;return *this;};
 ~C(){cout<<"finish C"<<endl;};
};

struct D{
 D(){cout<<"start D"<<endl;};
 D& operator=(const D&){cout<<"assign D"<<endl;return *this;};
 ~D(){cout<<"finish D"<<endl;};
};

struct E:
 A,B
{
 E(){cout<<"start E"<<endl;};
 ~E(){cout<<"finish E"<<endl;};
 C c;
 D d;
};

int main()
{
 E e1;
 endl(cout);
 {
  E e2=e1;
  e2=e1;
  endl(cout);
 };
 getch();
 return 0;
}

the observable result on borland builder6 and MS.net7 is identical on
windows console:

start A
start B
start C
start D
start E

assign A
assign B
assign C
assign D

finish E
finish D
finish C
finish B
finish A

from which we can see that the destructuction order of subobjects/data
members is reverse  to that of construction(just as expected ),but is
the behavoir of default assignment operator standard too? I mean is
there any guarantee that a std compiler default assigns subobjects/
data members  in the same order as the construction?

regards,
FM.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: =?iso-8859-1?q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Sun, 24 Jun 2007 12:40:16 CST
Raw View
On 24 Jun., 17:21, jam <farid.mehr...@gmail.com> wrote:
> #include<conio.h>

This is some non-standard header.

> #include<iostream.h>

Should probably be #include<iostream>, because
<iostream.h> was never part of the official standard.

> struct A{
>         A(){cout<<"start A"<<endl;};
>         A& operator=(const A&){cout<<"assign A"<<endl;return *this;};
>         ~A(){cout<<"finish A"<<endl;};
> };

You did not handle the copy c'tor. Was this an oversight or
by design?

> int main()
> {
>         E e1;
>         endl(cout);
>         {
>                 E e2=e1;

This one invokes the copy c'tor and thus should not
output anything.

>                 e2=e1;

OK, the copy-assignment operator.

> start A
> start B
> start C
> start D
> start E
>
> assign A
> assign B
> assign C
> assign D
>
> finish E
> finish D
> finish C
> finish B
> finish A
>
> from which we can see that the destructuction order of subobjects/data
> members is reverse  to that of construction(just as expected ),but is
> the behavoir of default assignment operator standard too? I mean is
> there any guarantee that a std compiler default assigns subobjects/
> data members  in the same order as the construction?

Yes, the order of member and base class invokations of the implicitely
generated copy-assignment operator is ruled by the standard. The
corresponding section is [class.copy], p. 13:

"The implicitly-defined copy assignment operator for class X performs
memberwise assignment of its subobjects. The direct base classes of
X are assigned first, in the order of their declaration in the base-
specifierlist,
and then the immediate nonstatic data members of X are assigned, in
the
order in which they were declared in the class definition.[..]"

Please note that only virtual base classes have some unspecified
parts of this assignment (I left this part out).

And yes, above rules match the rules for initialization of bases and
members inside any c'tor as described in [class.base.init].

Greetings from Bremen,

Daniel Kr   gler


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]