On Sun, Aug 12, 2012 at 10:12:46PM -0400, Andy Pintar wrote:
> I just destroyed the email I sas crafting and so this one will be a
> little more to-the-point.
> I mentioned before, Bruce Eckel's book is a great (free) place to
> start C++.  It will answer all the questions below.
> http://www.linuxguruz.org/ebooks/eckel/TICPP-2nd-ed-Vol-one.zip
> http://www.linuxguruz.org/ebooks/eckel/TICPP-2nd-ed-Vol-two.zip
> 
> 
> On Sat, 11 Aug 2012, Leslie S Satenstein wrote:
> >If you use the G++ compiler,  you can program with C++ and avoid classes,
> >have efficient code and except for the canned classes (namespace std) and
> >some others, gain as much performance as if coding in C.
> Well, if you don't include it you won't include it.  Just like in C
> you can use math, stdlib, string, etc.  But if you don't include
> them they won't be in your code.
> 
> >structures, unions, still work in C++.
> Structs are classes in C++.  So, a class with no methods is a struct
> with default private member variables.  Which seems kind of
> useless... class myClasss { public: int a; int b; }; is equivalent
> to struct myStruct { int a; int b; };
> 
> >I am not a strong C++ programmer, but if I declare a class, can I declare a
> >pointer of that class type and assign it to NULL or to any other object of
> >the same class?
> Yes.  myClass* myclassptr = new myClass( blah1 );
> delete myclassptr;
> myclassptr = null;
> myclassptr = new myClass( blah2 );A
> 
> >Can I do a memset(class_pointer, 0, sizeof(class));  To wipe out a class
> >with mixed binary and asciiz string variables, some of which are public and
> >some protected?
> Yes, you can.  private member variables just means that regular
> access is restricted.  But when you go memsetting you go around the
> protections c++ gives you.
> There was this whole argument about how
> c was somehow 'unsafe,' which is totally ridiculous if you ask me (I
> know you didn't, but there it is).  Programming is not safe.  In
> fact, if you could design a safe language where you couldn't shoot
> yourself in the foot, I bet it'd be useless.

You don't need a language that's absolutely safe, but one in 
which you can't shot yourself in the foot by accident.  Doing it 
deliberately is another matter entirely.

> Programming isn't
> easy.

No, it isn't.  Which is why I like to use powerful and efficient tools.
They make it possible to attack more difficult problems.

> Yes, memsetting a class to zero is really really stupid. But
> maybe just maybe there's a legitimate reason for doing so in this
> case.  The other 99.999999% of the time, just delete myclassptr;  Or
> better yet, use smart pointers (see "shared_ptr").  I have included
> a sample test program and the output at the bottom of this email.

-- hendrik

_______________________________________________
mlug mailing list
[email protected]
https://listes.koumbit.net/cgi-bin/mailman/listinfo/mlug-listserv.mlug.ca

Reply via email to