This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: How to prevent compiler-generated member functions?
- From: LLeweLLyn Reese <llewelly at lifesupport dot shutdown dot com>
- To: Nicolas F Rouquette <nicolas dot rouquette at jpl dot nasa dot gov>
- Cc: gcc-help at gcc dot gnu dot org
- Date: 21 Apr 2003 13:30:22 -0700
- Subject: Re: How to prevent compiler-generated member functions?
- References: <3EA4331A.3070900@jpl.nasa.gov>
- Reply-to: gcc-help at gcc dot gnu dot org
Nicolas F Rouquette <nicolas dot rouquette at jpl dot nasa dot gov> writes:
> Suppose we have this code:
>
> class foo {
> public:
> ~foo();
> };
>
> void bar()
> {
> foo f1; // (1)
> foo f2; // (1)
> f1 = f2; // (2)
> foo f3 = foo(); // (3)
> }
>
> Is there a compiler switch where (1), (2), (3) would all produce errors?
>
> (1) => no default constructor defined
> (2) => no copy assignment operator defined
> (3) => no copy constructor defined
>
> Without any flags, this code compiles cleanly.
I think this question is about C++, and not unique to gcc.
The way to prevent the compiler from generating these functions is to
delcare them:
class foo
{
foo(); //Private, and no definition provided.
//If used, there will be a compile time error.
foo(foo const&);//Likewise.
foo& operator=(foo const&);//Likewise.
public:
~foo();
};