Re: Default ctor, etc generated by compiler for structs?
JohnQ <johnqREMOVETHISprogrammer@yahoo.com> wrote in message...
Are a default constructor, destructor, copy constructor and assignment
operator generated by the compiler for a struct if they are not
explicitely
defined?
#include <vector>
struct Hmmm{ int mmm; };
{
std::vector<Hmmm> SVmmm(2);
std::vector<Hmmm> SVtwo;
SVtwo = SVmmm;
}
Can that work? Does it meet the requirements for a std container?
[ my tests say: yes, no problem, dude! ]
Now, add something non-simple to the struct, and test again.
I think the answer is yes, because "there is no difference between a
struct
and a class except the public/private access specification" (and a few
minor
other things). When I create a class, I always start by declaring the
default constructor, copy constructor and assignment operator private with
no implementation. I don't do that for structs though (I consider structs
like they were in C, but they really are not in the implementation as far
as
I know). I'm thinking that I don't handle structs the same because I trust
the compiler to do the right thing in the case of structs whereas bitwise
copy for a class may not be what is desired, for example.
Is the above reasoning OK? Should I continue NOT declaring/defining the
default stuff for structs?
John
class A{ public: int a;}; == struct A{ int a;};
class A{ int a;}; == struct A{ private: int a;};
Or did I misunderstand something (again!).
--
Bob R
POVrookie