OK. Then didn't you post the results like I asked? I'm taking the
trouble to answer your question. Won't you do me the courtesy of
responding to my reasonable request?
Please explain why only the following should
compile?
struct S {
private:
S();
};
struct T {
S s;
};
Because you didn't instantiate T. Until you do so, your compiler
doesn't see the error. Other compilers may issue a diagnostic there.
Yours doesn't. Either live with it or switch compilers.
If it compiles, then obviously the language designers have thought that
T is useful in some future context.
Are you ABSOLUTELY sure? Is it POSSIBLE that the compiler writer for
the compiler you were using decided it was easier not to check such
things until you tried to instantiate the class in question, since it
would only be a problem if you instantiated the class?
Care to explain what that might be apart from
creating pointers, assigning null to them and
comparing them (which could be accomplished
just as well with void pointers)?
Different compilers exhibit different behaviors. If you want a
compiler that gives you a diagnostic for the code you posted without
instantiating T, then switch to a compiler that does so, or ask the
writer of your compiler to make that change. In fact, I'm sure that if
you offer them enough money for their services, the compiler writers
will be happy to make that change for you. But that seems like a poor
use of your money, if you ask me. If you try to instantiate T, you get
a compile error, and if you don't try to instantiate T, then your
program never tries to access the inaccessible constructor.
Best regards,
Tom