Thursday, April 9, 2015

Digest for comp.lang.c++@googlegroups.com - 7 updates in 4 topics

Jorgen Grahn <grahn+nntp@snipabacken.se>: Apr 09 08:29PM

On Wed, 2015-04-08, 嘱 Tiib wrote:
>> >> virtual Fish* Clone()=0;
>> >> virtual void Swim()=0;
>> >> };
...
>> method, because we already have the means to make a copy...via the copy
>> constructor:
 
> It is not silly. Sometimes we need dynamic polymorphism in C++.
 
Undoubtedly ... but the OP is obviously a newbie, and the things
you're talking about is (should be) an advanced and late topic.
 
I have to agree with Mr Pisz: I sense Java, or Smalltalk, or whatever,
lurking in the background here. Continuing that path is not a good
way to learn how to use C++ well.
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
"Öö Tiib" <ootiib@hot.ee>: Apr 09 03:57PM -0700

On Thursday, 9 April 2015 23:29:41 UTC+3, Jorgen Grahn wrote:
 
> > It is not silly. Sometimes we need dynamic polymorphism in C++.
 
> Undoubtedly ... but the OP is obviously a newbie, and the things
> you're talking about is (should be) an advanced and late topic.
 
It should be advised that if there is hierarchy with virtual
functions and if objects in such have to be copied at all
then 'clone' is idiomatically the best of choices.
 
> I have to agree with Mr Pisz: I sense Java, or Smalltalk, or whatever,
> lurking in the background here. Continuing that path is not a good
> way to learn how to use C++ well.
 
Programmer has to have experience of debugging deep class hierarchy with
full yo yo of virtuals to realize how *not* to use C++ well. People
learn fastest from their own mistakes. Usage of other ways but
'clone' is one certain source of those headaches.
Doug Mika <dougmmika@gmail.com>: Apr 09 03:44PM -0700

I am having problems interpreting the following:
 
duckBilledP.Mammal::Animal::Age=25;
 
why not simply
duckBilledP.Animal::Age=25;
?
 
where we are given:
class Animal{
public:
int Age;
};
 
class Mammal:public Animal{};
class Platypus:public Mammal{};
 
int main(){
Platypus duckBilledP;
duckBilledP.Mammal::Animal::Age=25;
//duckBilledP.Animal::Age=25; //why wouldn't this work?
}
Robert Wessel <robertwessel2@yahoo.com>: Apr 09 03:44PM -0500

On Thu, 9 Apr 2015 09:00:46 -0700 (PDT), asetofsymbols@gmail.com
wrote:
 
>main(x){printf("%x",x);}
>Seems to me here would print 1
 
 
Even if this worked as (apparently) expected, the number printed would
depend on how the program was invoked.
Vir Campestris <vir.campestris@invalid.invalid>: Apr 09 09:54PM +0100

On 09/04/2015 14:06, Victor Bazarov wrote:
>> Is a valid C++ program
>> and what number it print...
 
> Not a valid C++ program.
 
Not valid - or just not compatible with any OS I ever came across?
 
(Win and *n?x seem to require argc and argv...)
 
Andy
Geoff <geoff@invalid.invalid>: Apr 09 02:22PM -0700

On Thu, 9 Apr 2015 09:00:46 -0700 (PDT), asetofsymbols@gmail.com
wrote:
 
>main(x){printf("%x",x);}
>Seems to me here would print 1
 
Why?
ram@zedat.fu-berlin.de (Stefan Ram): Apr 09 05:52PM

>>(Below, I use »N« for an end-of-line symbol in the source code.)
 
#include<iostream.h>N#include<bitset.h>Nint x;main(){bitset<16>a[]={21845,13107,3855,255};while(x<4)cout<<a[x++]<<"\n";}
#include<iostream>Nint main(){std::cout<<"0101010101010101\n0011001100110011\n0000111100001111\n0000000011111111\n";}
#include<iostream>Nint main(){for(int i=0;i<4;++i){for(int j=0;j<16;++j)std::cout<<j/(1<<i)%2;std::cout<<'\n';}}
#include<stdio.h>Nint main(){for(int i=0;i<4;++i){for(int j=0;j<16;++j)putchar('0'+j/(1<<i)%2);puts("");}}
 
(Nonportably, »'0'« might be replaced by »48«.)
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: