Hi,

        The following program :

#include <iostream>

class Clonable
{
public:
        virtual Clonable *      Clone() = 0;
};

class IsClonable : public Clonable
{
public:
        int             randomMember;

        Clonable *      Clone()
        {
                return new IsClonable;
        }
};

template <typename DERIVED>
class IsDerivedFrom
{
private:
        class           Yes {char a[1];};
        class           No  {char a[5];};

        static Yes      Test(Clonable *);
        static No       Test(...);

public:
        IsDerivedFrom()
        {
                cout << "Do nothing\n";
        }

        enum { dummy = sizeof(Test(static_cast<DERIVED *>(0))) ==
sizeof(Yes) ?
                0 : 1};
};

int main()
{
        IsDerivedFrom<IsClonable>       A;

        return 0;
}

        ..when compiled with g++ (2.95.2) dies with the following error :

clone.C: In instantiation of `IsDerivedFrom<IsClonable>':
clone.C:42:   instantiated from here
clone.C:42: invalid use of undefined type `class
IsDerivedFrom<IsClonable>'
clone.C:38: forward declaration of `class IsDerivedFrom<IsClonable>'

        When I asked for help on gnu.g++.help with this, the person who
responded to me said that (1) if the definitions of Yes, No, and Test were
moved into the namespace scope, then the program would compile (and it
does) and (2) the fact that this doesnt work in g++ (he said it failed
even in version 3.0) is a bug and that I should report it.

        Since I am not an expert C++ programmer, I leave it to you guys to
determine whether this is a bug. If it is, and you need me to open a bug
against the Debian package, let me know.

Thanks,
Jor-el



Reply via email to