Eliminating code duplication for static/nonstatic functions

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Sep 19 14:44:58 PDT 2013


On Thu, Sep 19, 2013 at 01:32:06PM -0700, Walter Bright wrote:
> On 9/19/2013 12:44 PM, Benjamin Thaut wrote:
> >Can't we make the compiler deduce the static attribute? If a template
> >method or a method of a template struct / class does not access any
> >of its members it becomes static automatically?
> 
> static/nonstatic member functions have different ABIs, so no, it would
> not work.

There's also the problem of base class methods turning static where you
didn't intend it to, for example:

	class Base {
		// This method is intended to be overridden by derived
		// classes.
		void method() {
			// Oops, didn't access 'this', now we're static.
			assert(0, "Not implemented");
		}
	}
	class Derived : Base {
		int x;
		override void method() { // NG
			x++;
		}
	}


T

-- 
Computers aren't intelligent; they only think they are.


More information about the Digitalmars-d mailing list