Bug in inheritance from template template parameters in VC7 
Author Message
 Bug in inheritance from template template parameters in VC7

The compiler works fine when all you want to do is instantiate the templated
parameter class as in the following example:

- - - - - - - - - - - - - - - - - - - - - - - -

class SomeClass {};
template<class T> class SomePolicy {};

template< template<class T> class PolicyClass>
class HostClass
{
public:
    void method()
    {
        PolicyClass<SomeClass> pc; // Instantiating 'PolicyClass Parameter
works fine here
    }

Quote:
};

int main()
{
    HostClass<SomePolicy> hc;
    hc.method();
    return 0;

Quote:
}

- - - - - - - - - - - - - - - - - - - - - - - -

But the compiler fails when you try to inherit from the templated parameter
like this:

- - - - - - - - - - - - - - - - - - - - - - - -

class SomeClass {};
template<class T> class SomePolicy {};

template< template<class T> class PolicyClass>
class HostClass : public PolicyClass<SomeClass> // Inheritance causes
compiler error C2504
{
public:
    void method()
    {
        PolicyClass<SomeClass> pc;
    }

Quote:
};

int main()
{
    HostClass<SomePolicy> hc;
    hc.method();
    return 0;

Quote:
}

- - - - - - - - - - - - - - - - - - - - - - - -

The full text of the error in Visual Studio is

- - - - - - - - - - - - - - - - - - - - - - - -

q:\dev\00-01\testvc7\main.cpp(8) : error C2504: 'PolicyClass<T>' : base
class undefined
        with
        [
            T=SomeClass
        ]
        q:\dev\00-01\testvc7\main.cpp(14) : see reference to class template
instantiation 'HostClass<PolicyClass>' being compiled
        with
        [
            PolicyClass=PolicyClass
        ]

- - - - - - - - - - - - - - - - - - - - - - - -

Both of the code samples compile without error using Comeau C++ version
4.2.45.1



Thu, 14 Aug 2003 05:57:07 GMT  
 Bug in inheritance from template template parameters in VC7
The compiler works fine when all you want to do is instantiate the templated
parameter class as in the following example:

- - - - - - - - - - - - - - - - - - - - - - - -

class SomeClass {};
template<class T> class SomePolicy {};

template< template<class T> class PolicyClass>
class HostClass
{
public:
    void method()
    {
        PolicyClass<SomeClass> pc; // Instantiating 'PolicyClass Parameter
works fine here
    }

Quote:
};

int main()
{
    HostClass<SomePolicy> hc;
    hc.method();
    return 0;

Quote:
}

- - - - - - - - - - - - - - - - - - - - - - - -

But the compiler fails when you try to inherit from the templated parameter
like this:

- - - - - - - - - - - - - - - - - - - - - - - -

class SomeClass {};
template<class T> class SomePolicy {};

template< template<class T> class PolicyClass>
class HostClass : public PolicyClass<SomeClass> // Inheritance causes
compiler error C2504
{
public:
    void method()
    {
        PolicyClass<SomeClass> pc;
    }

Quote:
};

int main()
{
    HostClass<SomePolicy> hc;
    hc.method();
    return 0;

Quote:
}

- - - - - - - - - - - - - - - - - - - - - - - -

The full text of the error in Visual Studio is

- - - - - - - - - - - - - - - - - - - - - - - -

q:\dev\00-01\testvc7\main.cpp(8) : error C2504: 'PolicyClass<T>' : base
class undefined
        with
        [
            T=SomeClass
        ]
        q:\dev\00-01\testvc7\main.cpp(14) : see reference to class template
instantiation 'HostClass<PolicyClass>' being compiled
        with
        [
            PolicyClass=PolicyClass
        ]

- - - - - - - - - - - - - - - - - - - - - - - -

Both of the code samples compile without error using Comeau C++ version
4.2.45.1



Thu, 14 Aug 2003 05:58:25 GMT  
 Bug in inheritance from template template parameters in VC7
The compiler works fine when all you want to do is instantiate the templated
parameter class as in the following example:

- - - - - - - - - - - - - - - - - - - - - - - -

class SomeClass {};
template<class T> class SomePolicy {};

template< template<class T> class PolicyClass>
class HostClass
{
public:
    void method()
    {
        PolicyClass<SomeClass> pc; // Instantiating 'PolicyClass Parameter
works fine here
    }

Quote:
};

int main()
{
    HostClass<SomePolicy> hc;
    hc.method();
    return 0;

Quote:
}

- - - - - - - - - - - - - - - - - - - - - - - -

But the compiler fails when you try to inherit from the templated parameter
like this:

- - - - - - - - - - - - - - - - - - - - - - - -

class SomeClass {};
template<class T> class SomePolicy {};

template< template<class T> class PolicyClass>
class HostClass : public PolicyClass<SomeClass> // Inheritance causes
compiler error C2504
{
public:
    void method()
    {
        PolicyClass<SomeClass> pc;
    }

Quote:
};

int main()
{
    HostClass<SomePolicy> hc;
    hc.method();
    return 0;

Quote:
}

- - - - - - - - - - - - - - - - - - - - - - - -

The full text of the error in Visual Studio is

- - - - - - - - - - - - - - - - - - - - - - - -

q:\dev\00-01\testvc7\main.cpp(8) : error C2504: 'PolicyClass<T>' : base
class undefined
        with
        [
            T=SomeClass
        ]
        q:\dev\00-01\testvc7\main.cpp(14) : see reference to class template
instantiation 'HostClass<PolicyClass>' being compiled
        with
        [
            PolicyClass=PolicyClass
        ]

- - - - - - - - - - - - - - - - - - - - - - - -

Both of the code samples compile without error using Comeau C++ version
4.2.45.1



Thu, 14 Aug 2003 05:59:48 GMT  
 Bug in inheritance from template template parameters in VC7
Charlie,
Quote:

> But the compiler fails when you try to inherit from the templated

parameter

Yep, sounds like a bug in the template template support. I presume it might
be related to another coupld of bugs in the implementation that were posted
to this group a week ago or so. Make sure you bug it.

Meanwhile, a simple workaround is to define HostClass like this:

template< template<class T> class PolicyClass, class A = SomeClass >
class HostClass : public PolicyClass<A>
{
public:
    void method()
    {
        PolicyClass<A> pc;
    }

Quote:
};

--
Tomas Restrepo [VC++ MVP]

http://www.mvps.org/windev/


Thu, 14 Aug 2003 22:56:29 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VC7 does NOT support template-template parameters involving non-type parameters

2. VC 7.1 final beta: bug with template template parameters

3. Possible bug with template template parameters in VC++ 7.0

4. VC7.1 C++ bug: incorrect definition of the constructor of a template accepted

5. template template parameter with default value (VS.NET 2003)

6. VC7 bug: static member templates

7. Templates as a templates-parameters

8. Template class as template parameter

9. template template parameters

10. template with template parameter

11. template template parameter that VC++ does NOT support

12. Template Template Parameters

 

 
Powered by phpBB® Forum Software