class template conflict

Neia Neutuladh neia at ikeran.org
Tue Dec 25 16:55:36 UTC 2018


On Tue, 25 Dec 2018 13:03:13 +0000, Michelle Long wrote:
> But I am not talking about inside the template being used. The whole
> point of doing this is so that one can refer to the base class using the
> same name as the derived with a template parameter to make a composite
> structure.

The following are entirely equivalent:

    class X(int N) : X {}

    template X(int N)
    {
      class X : X {}
    }

You want to be able to do, essentially:

    class X {}
    template X(int N)
    {
      // `: X` somehow refers to the X in the outer scope
      class X : X {}
    }

And sure, this specific case obviously doesn't work if the `: X` refers to 
the template or the class inside the template. But the symbol lookup rules 
aren't "try everything and see what sticks". You look up the nearest 
symbol and then you just use that.

It would be like arguing that, in the following example, the compiler 
should know that ints aren't callable and should call the function:

    void foo() { writeln("merr critmis"); }
    void main()
    {
        int foo = 10;
        foo();
    }

Which isn't obviously wrong, but it does make things harder to understand.


More information about the Digitalmars-d-learn mailing list