Feature request for vtable emitter

Jason Gunthorpe jgg@gpu.srv.ualberta.ca
Wed Dec 10 10:53:00 GMT 1997


On Wed, 10 Dec 1997, Klaus-Georg Adams wrote:

> >>>>> "Jason" == Jason Gunthorpe <jgg@gpu.srv.ualberta.ca> writes:
> 
> [...]
> 
>     >> No, because non-virtual member functions don't have to be
>     >> defined.
> 
>     Jason> Erm, but who on earth would actually do that? :>
> 
> I do this all the time to prevent generation of implicit default and
> copy ctors and assignment operators if I don't want them:
> 
> class myClass {
> public:
> 	myClass(int) {}
> 	void whatever() {}
> private:
> 	// The following are never defined, they give link errors
> 	// if you try to use them.
> 	myClass();
> 	myClass( const myClass& );
> 	myClass& operator=( const myClass& );
> };

My understanding is that the better solution is simply:
 
 private:
    myClass() {};
    myClass(const myClass &) {}; 
    myClass &operator =(const myClass &) {};

This will only allow functions within the class to call these functions
(they are private). Of course if you actually want to prevent use within
the class that is different. The usual need I have seen for this is to
prevent -users- from using the functions, the class author can be carefull
enough to advoid them.

If stuff like this is the only reason to limit the definition of the class
base member to virtual function I would really like to see it made an
option, those of us who don't use this technique can safely enable it and
speed up the compiler and shrink down the .o files.

Thanks,
Jason




More information about the Gcc-bugs mailing list