J
JohnQ
I like, non-copyable, non-assignable and, most often,
non-default-constructable also, as a starting point for class design:
class SomeClass
{
SomeClass(); // disallow default construction
SomeClass(const SomeClass&); // disallow copy construction
SomeClass& operator=(const SomeClass&); // disallow assignment
public:
// other allowed constructors, destructor, operators, functions
} ;
I'm swaying toward the thought that compiler-generated functions are a pain
and go against logical language design: when not specified, a default
constructor, a destructor, a copy constructor and an assignment operator are
generated by the compiler. But to prevent them, you have to do typing as
shown above, leaving out the implementation. Wouldn't it make more sense to
say, "If it's not declared in the class declaration, then the class object
instances will not have the behavior in the compiled code"? How
counter-intuitive can one be?! To me, "what you see is what you get" seems
better. Is there a good reason why it is like it is or could it have just as
easily gone the other way? Which way would you prefer?
John
non-default-constructable also, as a starting point for class design:
class SomeClass
{
SomeClass(); // disallow default construction
SomeClass(const SomeClass&); // disallow copy construction
SomeClass& operator=(const SomeClass&); // disallow assignment
public:
// other allowed constructors, destructor, operators, functions
} ;
I'm swaying toward the thought that compiler-generated functions are a pain
and go against logical language design: when not specified, a default
constructor, a destructor, a copy constructor and an assignment operator are
generated by the compiler. But to prevent them, you have to do typing as
shown above, leaving out the implementation. Wouldn't it make more sense to
say, "If it's not declared in the class declaration, then the class object
instances will not have the behavior in the compiled code"? How
counter-intuitive can one be?! To me, "what you see is what you get" seems
better. Is there a good reason why it is like it is or could it have just as
easily gone the other way? Which way would you prefer?
John